Reply To: Looking for similar filter to pre_get_posts but for bp_search
Unfortunately BuddyPress search doesn’t use WP_Query.
The best you can do with BuddyPress search is to use the bp_search_query_results filter.
function bp_exclude_from_search( $search_results ) {
return array_filter( $search_results, function( $result ) {
$excluded_post_ids = array( 1, 2, 3 );
$excluded_post_types = array( 'custom_type', 'other_cpt' );
if (
! in_array( get_post_type( $result->id, $excluded_post_ids ) )
|| ! in_array( get_post_type( $result->type, $excluded_post_types ) )
) {
return true;
};
});
};
add_filter( 'bp_search_query_results', 'bp_exclude_from_search', 10 );