Skip to:
Content
Pages
Categories
Search
Top
Bottom

Looking for similar filter to pre_get_posts but for bp_search

  • @huesoamz

    Participant

    Hi,

    I could modify the currect query of the WP Core search using the filter of pre_get_posts but in the case of bp_search I cannot, is any filter that I could use to modify the results/query when we use the Buddypress search instead of WordPress Search? ?s=clean&subset=pages&bp_search=1

    I need to exclude some pages/post or custom types, maybe ID’s in general from the BuddyPress Search, but I dont wanna to install another plugin, I prefer to have the control under function.php for example,

    Is any filter that allow to modify the query as “pre_get_post” did ?

    thanks in advance

Viewing 1 replies (of 1 total)
  • @mediaformat

    Participant

    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 );
    
Viewing 1 replies (of 1 total)
  • You must be logged in to reply to this topic.
Skip to toolbar