Skip to:
Content
Pages
Categories
Search
Top
Bottom

Add you blog search to the search

  • Avatar of yairnazz
    yairnazz
    Participant

    @yairnazz

    When you first download buddypress there is a search bar at the top of the screen that holds a search for members, groups, blogs, how can i change the search blogs option to search posts on website?

Viewing 12 replies - 1 through 12 (of 12 total)
  • Avatar of r-a-y
    r-a-y
    Moderator

    @r-a-y

    The BP search form is generated from the bp_search_form() function.

    Short answer is you can’t modify that function.

    But you can add this to your BP member theme:

    <form method="get" id="searchform" action="<?php bloginfo('url'); ?>/">
    <label class="hidden" for="s"><?php _e('Search for:'); ?></label>
    <div><input type="text" value="<?php the_search_query(); ?>" name="s" id="s" />
    <input type="submit" id="searchsubmit" value="Search" />
    </div>
    </form>

    Copied and pasted from default Kubrick WP theme.

    That should work, but report back and let me know.

    Avatar of yairnazz
    yairnazz
    Participant

    @yairnazz

    Well i actually want it to be in the menu like when you click on the box a scroll box comes down saying search members, groups, posts i dont want 2 separate searches.

    Avatar of r-a-y
    r-a-y
    Moderator

    @r-a-y

    That’s a little harder because they use two separate form actions.

    You could get creative and do a javascript toggle… but I can’t help you with that… at least not with the time I have right now!

    Maybe someone can jump in and code something fast.

    Avatar of yairnazz
    yairnazz
    Participant

    @yairnazz

    Well if you need the code…. does this help

    function bp_search_form_type_select() {
    // Eventually this won't be needed and a page will be built to integrate all search results.
    $selection_box = '<select name="search-which" id="search-which" >';

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

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

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

    $selection_box .= '</select>';

    return apply_filters( 'bp_search_form_type_select', $selection_box );
    }

    function bp_search_form() {
    $form = '
    <form action="' . bp_search_form_action() . '" method="post" id="search-form">
    <input type="text" id="search-terms" name="search-terms" value="" />
    ' . bp_search_form_type_select() . '

    <input type="submit" name="search-submit" id="search-submit" value="' . __( 'Search', 'buddypress' ) . '" />
    ' . wp_nonce_field( 'bp_search_form' ) . '
    </form>
    ';

    echo apply_filters( 'bp_search_form', $form );
    }

    Avatar of r-a-y
    r-a-y
    Moderator

    @r-a-y

    I know the code… you’re basically asking to combine two form actions, which is a little complicated without doing some manipulation and coding your own function.

    Avatar of yairnazz
    yairnazz
    Participant

    @yairnazz

    :( someone help please

    Avatar of Svenl77
    Svenl77
    Participant

    @svenl77

    Because I need it and I don’t want spend much time getting into it, I just use the static way. May be not the correct way to do it, but for me it’s working.

    <script type=”text/javascript”>

    function check_search_url() {

    var form = document.getElementById(‘search-form’);

    var which = document.getElementById(‘search-which’);

    var terms = document.getElementById(‘search-terms’);

    if( which.selectedIndex == 0 ) {

    form.setAttribute(“action”,”http://yourdomain.com/?s=”+terms.value) ;

    }

    }

    </script>

    <form id=”search-form” method=”post” action=”http://yourdomain.com/search”>

    <input type=”text” value=”” name=”search-terms” id=”search-terms”/>

    <select id=”search-which” name=”search-which”>

    <option value=”blog”>Blog</option>

    <option value=”blogs”>Blogs</option>

    <option value=”members”>Mitglieder</option>

    <option value=”groups”>Gruppen</option>

    <option value=”forum”>Forum</option>

    </select>

    <input type=”submit” onclick=”check_search_url()” value=”Suche” id=”search-submit” name=”search-submit”/>

    </form>

    @Svenl77

    i have an idea that i want you to comment on. please respond.

    modify searchform.php with the custom search code (sorry but i’m referring to Google here just for site wide search) having only single box+button only, i.e no dropdown menu.

    modify search.php with the custom search result code, putting the results from the members, blogs, forums and groups search in their respective tabs with ajax.

    This way user skips a step and also gets a better looking simple search box.

    This shall do the trick like it did in WP and WPMU. Later on someone clever (like you and not me) could probably put a plugin to do that.

    Avatar of shaisimchi
    shaisimchi
    Participant

    @shaisimchi

    I hope someone here already have a solution to this:

    I am running wordpress MU with buddypress on top.

    I have added the bp-events plugin.

    Currently the search bar will only search members and groups and I would like for it to search through events too.

    When I choose members in the dropdown list with the string x I see the following URL being called: http://mydomain.com/wpmu/members/?s=x

    When I choose groups in the dropdown list with the string y I see the following URL being called: http://mydomain.com/wpmu/groups/?s=y

    I have edited the file that builds the dropdown list and now it also contains the Events option but when I choose that option for some reason the URL being caled when I search for event z is: http://mydomain.com/wpmu/members/?s=z

    I am not sure what I am doing wrong but it seems after my debugging that a parameter called _wp_http_referer is not getting the right value when the Events option is selected. instead of being wpmu/events/?s=z it is changing to wpmu/members/?s=z and this is what causing the URL to be wrong.

    It would be great if someone can point me to a solution or to what I am doing wrong.

    Thanks,

    Shai

    Avatar of Pedro Miguel
    Pedro Miguel
    Participant

    @pedromiguel

    ok, found the solution, I will also submit a ticket on trac

    on bp-core-tempaltetags.php change this:

    function bp_search_form_type_select() {
    // Eventually this won't be needed and a page will be built to integrate all search results.
    $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>';
    }

    to this:

    function bp_search_form_type_select() {
    // Eventually this won't be needed and a page will be built to integrate all search results.
    $selection_box = '<select name="search-which" id="search-which" style="width: auto">';
    $selection_box .= '<option value="blog">' . __( 'Blog', 'buddypress' ) . '</option>';

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

    and on bp-core.php

    change this:

    if ( !$slug || empty( $slug ) ) {
    switch ( $search_which ) {
    case 'members': default:
    $slug = BP_MEMBERS_SLUG;
    $var = '/?s=';
    break;

    to this:

    if ( !$slug || empty( $slug ) ) {
    switch ( $search_which ) {
    case 'blog': default:
    $slug = '';
    $var = '/?s=';
    break;
    case 'members':
    $slug = BP_MEMBERS_SLUG;
    $var = '/?s=';
    break;

    Avatar of Pedro Miguel
    Pedro Miguel
    Participant

    @pedromiguel

    @apeatling

    Its possible to change this on core or you want the search function on plugin just to bp?

    Avatar of b_stewart
    b_stewart
    Member

    @b_stewart

    @shaisimchi

    To integrate the BuddyPress Events plugin (bp-events) to the search is very similar to the code Pedro posted.

    on bp-core-tempaltetags.php change this:

    function bp_search_form_type_select() {
    // Eventually this won't be needed and a page will be built to integrate all search results.
    $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>';
    }

    to this:

    function bp_search_form_type_select() {
    // Eventually this won't be needed and a page will be built to integrate all search results.
    $selection_box = '<select name="search-which" id="search-which" style="width: auto">';
    $selection_box .= '<option value="events">' . __( 'Events', 'buddypress' ) . '</option>';

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

    and on bp-core.php

    change this:

    if ( !$slug || empty( $slug ) ) {
    switch ( $search_which ) {
    case 'members': default:
    $slug = BP_MEMBERS_SLUG;
    $var = '/?s=';
    break;

    to this:

    if ( !$slug || empty( $slug ) ) {
    switch ( $search_which ) {
    case 'members': default:
    $slug = BP_MEMBERS_SLUG;
    $var = '/?s=';
    break;
    case 'events':
    $slug = BP_EVENTS_SLUG;
    $var = '/?s=';
    break;

    Hopefully that helps someone out.

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

You must be logged in to reply to this topic.