Helping you Build Your Own Social Network!

Faster, better and easier!

Activity Search

(7 posts) (3 voices)

Tags:

No tags yet.


  1. Hi,

    I need to add Activity Search to my BP search dropdown select menu. Is anyone already done this enhancement ?

    Thanks.
    Guillaume.

    Posted 1 year ago #
  2. Nobody ?

    Posted 1 year ago #
  3. Bump

    Posted 1 year ago #
  4. Hi,
    Sorry for not posting earlier.
    Please put this code in your bp-custom.php and It will do exactly as you want. allow you to add a drop down to select box and then search activity

    //add activity drop down
    add_filter( 'bp_search_form_type_select', "bp_include_activity_dd" );
    
    /* activity drop down*/
    function bp_include_activity_dd($search_box) {
    	$selection_box = '';
            if(bp_is_active("activity")){
                	$selection_box .= '<option value="activity">' . __( 'Activity', 'buddypress' ) . '</option></select>';
    
            $search_box=str_replace("</select>", $selection_box, $search_box);
            }
    
    return $search_box;
    }
    
    //for searching on activity page
    add_filter("bp_core_search_site","bp_search_for_activity",10,2);
    
    function bp_search_for_activity($url,$search_terms){
    $search_which = $_POST['search-which'];
    if($search_which=="activity")
     $url =  site_url( BP_ACTIVITY_SLUG .'/?s=' . urlencode($search_terms) );
    
    return $url;
    
    }
    
    //since bp do not provide a hook to set custom search string, manipulate using ajax_querystring
    
    add_filter("bp_dtheme_ajax_querystring","bp_add_activity_search_to_query");
    
    function bp_add_activity_search_to_query($qs){
    if(empty($qs)&&!empty($_REQUEST['s']))
        $qs="search_terms=".$_REQUEST['s'];
    
    return $qs;
    
    }

    It will work if you are using default theme or have the "bp_dtheme_ajax_querystring" filter in your custom theme , otherwise It may not work.

    Please let me know how it goes with you.

    Posted 1 year ago #
  5. @Brajesh

    Wouldn't it be cool to have a similar function in global search?
    (hint...)

    :-)

    Posted 1 year ago #
  6. Hi,

    Yes, it works. The problem is I have already customize the drop down menu with the code below, and it seems to make conflict. If I remove the code below, it works, if not, it doesn't work.

    //filter the allowed search type
    add_filter("bp_search_form_type_select","bpdev_allowed_search_type");
    function bpdev_allowed_search_type($selecttion_box_old){
    //ignore the selection box
    $selection_box = '<select name="search-which" id="search-which" style="width: auto">';

    if ( function_exists( 'xprofile_install' ) ) {
    $selection_box .= '<option value="members">' . __( 'Members', 'buddypress' ) . '</option>';
    }

    if ( function_exists( 'groups_install' ) ) {
    $selection_box .= '<option value="groups">' . __( 'Groups', 'buddypress' ) . '</option>';
    }

    if ( function_exists( 'bp_forums_setup' ) && !(int) get_site_option( 'bp-disable-forum-directory' ) ) {
    $selection_box .= '<option value="forums">' . __( 'Forums', 'buddypress' ) . '</option>';
    }
    //here we modify the thing to a new type posts
    $selection_box .= '<option value="posts">' . __( 'Blog', 'buddypress' ) . '</option>';

    $selection_box .= '</select>';
    return $selection_box;
    }
    //let us filter the search action urls
    add_filter("bp_core_search_site","bpdev_filter_search_url");
    function bpdev_filter_search_url($search_url){
    //if user is searching for main site content, modify url else return url
    $search_terms = $_POST['search-terms'];
    $search_which = $_POST['search-which'];
    if($search_which=="posts")
    $search_url=site_url( "?s=". urlencode($search_terms) );
    return $search_url;

    Almost, I need search box on activity page, as member and group page. Do you know how to add this ?

    Posted 1 year ago #
  7. Do you know how to add this to your unified search ?

    Posted 1 year ago #

Reply

You must log in to post.