Introduction
The BuddyBoss Platform does not provide a built-in setting to exclude specific posts from the search results in BBP (BuddyPress/BuddyBoss). You can achieve this using a small custom function added to your active theme. This guide explains how you can exclude certain posts from the BBP Search Feature.
Custom Workaround
Before proceeding, make sure you have a complete site backup.
- Go to Appearance > Theme Editor in your WordPress admin dashboard.
- Under Select theme to edit, choose your active theme (preferably a BuddyBoss Child Theme), then click Select.
- From the Theme Files list, open Theme Functions (functions.php).
- Add the following code just before the closing PHP tag (?>):
function bb_change_search_results_posts( $query ) {
if ( ! is_admin() && bp_search_is_search() && ( 'post' == $query->get('post_type') ) ) {
// IDs of posts to exclude
$remove_items = array(281, 1794);
// Get current included post IDs (if any)
$post_ids = $query->get('post__in');
// Remove specified posts from search results
$query->set( 'post__in', array_diff( (array) $post_ids, $remove_items ) );
}
return $query;
}
add_action( 'pre_get_posts', 'bb_change_search_results_posts', 9999 );
- Click Update File to save the changes.
This code uses WordPress’s pre_get_posts filter to modify the search query before results are displayed.
Troubleshooting and FAQs
Q: The excluded posts are still showing in search results.
A: Make sure you added the code to your child theme’s functions.php file and not the parent theme. Clear your site cache and refresh the search page.
Q: Can I exclude more posts later?
A: Yes. Simply add their post IDs to the $remove_items array.
Q: Will this affect admin searches?
A: No. The code only modifies front-end BuddyBoss search results.
Q: Can I revert this change easily?
A: Yes. Remove or comment out the code from functions.php and save the file.