How to make bbPress topics searchable in wordpress search

As we all know wordpress provides a basic search function.
And also bbPress provides a ‘search bbPress’ function.


Running two different search possibilites is not very smart.

Here is how you can combine these two search functions.

In the following are 3 functions that allow to search for bbPress content in the default wordpress search – I recommend to use all of them.

Just copy the code and add it to the bottom of your functions.php.

1. Include bbPress topics in wordpress search results

/**
 * Include bbPress 'topic' custom post type in WordPress' search results */
 
function ntwb_bbp_topic_cpt_search( $topic_search ) {
	$topic_search['exclude_from_search'] = false;
	return $topic_search;
}
add_filter( 'bbp_register_topic_post_type', 'ntwb_bbp_topic_cpt_search' );

2. Include bbPress forums in wordpress search results

/**
 * Include bbPress 'forum' custom post type in WordPress' search results */

function ntwb_bbp_forum_cpt_search( $forum_search ) {
	$forum_search['exclude_from_search'] = false;
	return $forum_search;
}
add_filter( 'bbp_register_forum_post_type', 'ntwb_bbp_forum_cpt_search' );

3. Include bbPress replies in wordpress search results

/**
 * Include bbPress 'reply' custom post type in WordPress' search results  */

function ntwb_bbp_reply_cpt_search( $reply_search ) {
	$reply_search['exclude_from_search'] = false;
	return $reply_search;
}
add_filter( 'bbp_register_reply_post_type', 'ntwb_bbp_reply_cpt_search' );

When this is done, I would remove the ‘bbpress search’ if you have enabled it somewhere on your page through a widget.

Now your normal wordpress search contains bbPress content!

That’s it 🙂
Enjoy!

Leave a Reply

avatar
wpDiscuz