Site logo

Archived topic

bbpress search in nav search bar

4 replies · Started by Simon Wagemyr on June 1, 2021

Viewing posts 1–5 of 5

Hi!
Is there any way to get the normal search to also show bbpress forum topics/replies?

Hi there,

By normal search, are you referring to the navigation search or WordPress' search widget?

I can't speak for the OP, but I'm trying to find the answer for including topics & replies in the navigation search...

Sorry for ghosting, I found something that works for now and got distracted.

My current method is Relevanssi mod, but it feels like it shouldn't be necessary.

The goal is as Melissa described!

@Simon- I finally got it.

Add the following code to your functions.php

add_filter( 'generate_navigation_search_output', function() {
    printf(  
        '<form method="get" class="search-form navigation-search" action="%1$s">
            <input type="search" class="search-field" value="%2$s" name="s" title="%3$s" />
            <input type="hidden" name="post_type[]" value="post" />
            <input type="hidden" name="post_type[]" value="topic" />
            <input type="hidden" name="post_type[]" value="reply" />
        </form>', 
        esc_url( home_url( '/' ) ), 
        esc_attr( get_search_query() ),   
        esc_attr_x( 'Search', 'label', 'generatepress' ) 
    ); 
} );

If you want to make it faster, either comment out or completely remove the reply line:

// <input type="hidden" name="post_type[]" value="reply" />

It's still not superfast having to search all of the topics, particularly if you have a large database.

This archived topic is closed to new replies.