WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I placed the following code into my functions.php file:

function filter_search($query) {
    if ($query->is_search) {
    $query->set('post_type', array('topic', 'reply'));
    };
    return $query;
};
add_filter('pre_get_posts', 'filter_search');

With that code I can only search for the reply custom post type (results with the topic custom post type don't show up).

Both are custom post types from the bbpress 2.0 plugin.

I have to do this:

$query->set('post_type', array('topic'));

in order to make the topic custom post type show up (but them I no longer get the reply custom post type to show up in the results).

Any suggestions to fix this?

share|improve this question

Try to drop that in your functions.php file:

function filter_query_for_search( $query ) {
    if ( isset( $query['s'] ) ) {
        $query['post_type'] = array('forum', 'topic', 'reply', 'any');
    }
    return $query;
}

add_filter('request', 'filter_query_for_search', 1);

that would hook into the query just before its being executed.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.