1. Home
  2. Knowledge Base
  3. Customizations
  4. PHP Functions
  5. How to Exclude Certain Posts from the BBP Search Feature

How to Exclude Certain Posts from the BBP Search Feature

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.

  1. Go to Appearance > Theme Editor in your WordPress admin dashboard.
  2. Under Select theme to edit, choose your active theme (preferably a BuddyBoss Child Theme), then click Select.
  3. From the Theme Files list, open Theme Functions (functions.php).
  4. 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 );

Note: Replace 281 and 1794 with the post IDs you want to exclude. You can add more IDs as needed.

  1. 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.

Note: Modifications are typically considered custom work, but we are making an exception in this case. Please review the BuddyBoss Support Policy.

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.

Was this article helpful?

Related Articles

Subscribe to Our Newsletter

Stay In Touch

Subscribe to our Newsletter, and we’ll send you the latest news from BuddyBoss

  • This field is hidden when viewing the form
  • This field is for validation purposes and should be left unchanged.

To speak to our Agency consultant, fill in the form found at our Contact Page.

  • Get Started

    Enter your name and email address to get started with your project...

  • This field is for validation purposes and should be left unchanged.