Posts from category not displaying when searching for category name

I’m having trouble with my search results page in that it is not displaying posts that are a part of a category when searching for the category name. For Instance, If I search for “doors” (which is a cat) all Partners that are in the “doors” category should be displayed in the search results. Right now, only partners that have the word “doors” in their title or content is displayed.

I’m running a searchAll function so the the standard wp search will search everything.

Read More
// Define what post types to search
function searchAll( $query ) {
if ( $query->is_search ) {
    $query->set( 'post_type', array( 'post', 'page', 'feed', 'partner','project', 'press', 'review' ));
}
return $query;
}
// The hook needed to search ALL content
add_filter( 'the_search_query', 'searchAll' );

What am I missing?

Related posts

Leave a Reply

2 comments

  1. your query is seraching for post_type, not category_name.

    post_type is used for custom post types or taxonomies ..

    your query should contain $query->set( 'category_name', array( 'post', 'page', 'feed', 'partner','project', 'press', 'review' ));

    however, in some cases (and I do not know the reason) that would not work for sub-categories.
    in that case, you should use category-slug (slug) insted.

  2. Ive changed my string to this:

    <?php
    // Define what post types to search
    function searchAll( $query ) {
        if ( $query->is_search ) {
            $query->set( 'category_name', array( 'post', 'page', 'feed', 'partner','project', 'press', 'review' ));
        }
    
        return $query;
    }
    
    // The hook needed to search ALL content
    add_filter( 'pre_get_posts', 'searchAll' );
    

    I do have custom taxonomies though. Basically I’m trying to create a “Search everything” function.