Skip to:
Content
Pages
Categories
Search
Top
Bottom

BBP Results Showing in WordPress search

  • @mchl

    Participant

    My site is running mainly CPTs but I filter my search results to a subset of these using this technique:

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

    which works fine for wordpress but when I search within BBP i get the ‘Oh bother! No search results were found here!’ message as you’d expect because of the above filter.

    If i remove the filter the BBP search works fine, and if I add ‘forum’, ‘topic’, ‘reply’ to the above filter BBP search works fine, but the problem is get I the forum results appearing in the main search results page.

    Also, If i remove the filter all together I still get forum results appearing in the main results page.

    Is there a way to exclude forums results from appearing in the main search?

Viewing 5 replies - 1 through 5 (of 5 total)
  • @robin-w

    Moderator

    bbpress sets the post_type =
    array( bbp_get_forum_post_type(), bbp_get_topic_post_type(), bbp_get_reply_post_type() );

    so if post type = that, then you know you are in a forum search, so you could add a line in your filter to check if $query->post_type equals array( bbp_get_forum_post_type(), bbp_get_topic_post_type(), bbp_get_reply_post_type() ) then just return query?

    @mchl

    Participant

    Cheers for the response. Figured out a simple way to handle it.

    When I register the CPTs i just need to define exclude_from_search' => true for the CPTs I don’t want to appear in the WP search, then i dont need to run the above filter and BBP looks after itself.

    @robin-w

    Moderator

    great, glad you are fixed !

    @tazogamer

    Participant

    Solution for: “Oh bother! No search results were found here!”

    Forum search does not work in 2.3.2

    @pazzaglia1

    Participant

    I used the first code snippet above in my functions.php with ‘post’,’page’,’topic’ in the array. It DID show the topics in search results BUT, unfortunately, it blanked-out my topic page (no topic or reply text just the title and reply form).

    However, I took a chance and installed the super-old “Search bbPress” plug-in and edited the script to NOT add ‘replies’ to the search results and it worked!

    Thought I’d share my experience in case anyone else has been hunting for a solution to this for weeks, like me.

    Ciao,

    L

Viewing 5 replies - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.
Skip to toolbar