Skip to:
Content
Pages
Categories
Search
Top
Bottom

Re: Remove Blog from Search Bar


Brajesh Singh
Participant

@sbrajesh

Ok,here is the solution.

This will sllow user to search for the blog posts on the main site only.

I have used two hooks to accomplish the purpose.

put this code in either bp-custom.php or in functions.php of your current theme. No core modification is required.

//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;
}

Skip to toolbar