/*Reverse sticky header*/
  1. Home
  2. Knowledge Base
  3. Customizations
  4. PHP Functions
  5. Exclude Certain Posts from the BBP Search Feature

Exclude Certain Posts from the BBP Search Feature

By default, the platform does not have this option. You can use the following function code to redirect to the profile after a user logs in.

Please follow the steps below:

1. Go to Appearance > Theme Editor.

2. Under “Select theme to edit”, choose (BuddyBoss Child/whatever theme is active), then click “Select”.

3. Below Theme Files, select Theme Functions (functions.php).

4. Append the code just before the closing PHP tag “?>”:

To make it work, you can make use of the pre_get_posts filter https://developer.wordpress.org/reference/hooks/pre_get_posts/

An example: This will remove the post IDs 281 and 1794 from search results. Kindly test it and change it according to your needs.

function bb_change_search_results_posts( $query ) { if ( ! is_admin() && bp_search_is_search() && ( 'post' == $query->get('post_type') ) ) { $post_ids = $query->get('post__in'); $remove_items = array(281, 1794); $query->set( 'post__in', array_diff( $post_ids, $remove_items) ); } return $query; } add_action( 'pre_get_posts', 'bb_change_search_results_posts', 9999 );

5. Click Update File to save the changes.

Note: Any modifications are considered as custom work already. Know more about our Support Policy here: https://www.buddyboss.com/support-policy/

Was this article helpful?

Related Articles

Need Support?

Can't find the answer you're looking for?
Contact Support

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

"*" indicates required fields

Get Started

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

Name*