Skip to:
Content
Pages
Categories
Search
Top
Bottom

Remove Blog from Search Bar


  • Henry
    Participant

    @henrybaum

    Given that I don’t allow new blog registration, having Blog in the search bar drop-down (which includes members, groups, forums, and blogs) is going to confuse people. Any way to set this so it’s for Posts instead and searches on-site blog posts?

Viewing 10 replies - 1 through 10 (of 10 total)

  • Henry
    Participant

    @henrybaum

    Amending this issue – the blog search should work to search the one blog affiliated with the site – the main URL – but searching via blog comes up with nothing, regardless of the search string.


    Henry
    Participant

    @henrybaum

    OK, progress. It’s in bp-core-templatetags.php

    if ( function_exists( ‘bp_blogs_install’ ) ) {

    $selection_box .= ‘<option value=”blogs”>’ . __( ‘Blogs’, ‘buddypress’ ) . ‘</option>’;

    }

    I can delete that, but any idea how to configure this so that the drop down allows a search of posts, rather than blogs?


    Xevo
    Participant

    @xevo

    The value is what’s important, not what’s between the option tags. You could easily change it to something like this.

    <option value="blogs">Posts</option>


    Henry
    Participant

    @henrybaum

    But that still searches blogs, not posts (and nothing comes up for blogs anyway, no matter what the search). I’d be happy with a sitewide search including members, forums, and groups, and posts and list it as Site.


    koms
    Participant

    @koms

    henrybaum,

    I’m also looking for the same. Please share here if you find solution for that.


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


    Henry
    Participant

    @henrybaum

    Tried that. No go.


    jivany
    Participant

    @jivany

    What about Brajesh’s solution doesn’t work for you? I just implemented virtually the same thing (without the filtering of the search action urls) and the drop down box only contains Members/Groups/Forums now.

    Brajesh: what does the search action url filter do? I’m not following the intent.

    Thanks!


    Brajesh Singh
    Participant

    @sbrajesh

    well

    let me clarify

    My Intention was You do not need to modify the core.

    To change the dropdown box, I have used the filter “bp_search_form_type_select”

    and since buddypress traps the search url and makes a redirect accordingly, so “bp_core_search_site” works with that and redirects correctly.

    @henrybaum, what Is appearing in your drop down box(Is it members, groups, forums, Blog), select blog and try the search. Is buddypress on your root domain.

    PS:Please Note if you have put the code correctly, The ‘Blogs’ will be replaced by ‘Blog’


    jivany
    Participant

    @jivany

    Thanks for the info Brajesh. Your solution makes sense to me now. :)

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Remove Blog from Search Bar’ is closed to new replies.
Skip to toolbar