Skip to:
Content
Pages
Categories
Search
Top
Bottom

WP Pages that displays a specified member directory search results

Viewing 5 replies - 1 through 5 (of 5 total)
  • Avatar of Slava UA
    Slava UA
    Participant

    @slaffik

    Open members/members-loop.php file in your theme.
    Copy its code and paste into your page template file.
    Find this string in that code:
    `bp_has_members( bp_ajax_querystring( ‘members’ )`
    Change it to smth like this:
    `bp_has_members(array(‘search_terms’ => ‘virginia beach’))`

    PS Open `/buddypress/bp-members/bp-members-template.php` file, line 264, to see all possible values that you can pass to a function.

    Avatar of Slava UA
    Slava UA
    Participant

    @slaffik

    Take care of quotes, they were converted in a wrong way in the snippet above.

    Avatar of Biswadip
    Biswadip
    Participant

    @biswadip

    Thank you that was very helpful.

    How do I submit a query from the members search form to bring up the appropriate listing in the manner mentioned above? At the moment I can only search for members when the search form submits to the members directory. What I want to do is that when a user submits a search query from a search form on this page:

    http://website/custom-page/

    the results from the query:

    http://website/members/?s=term-searched-for

    are displayed on the same custom page hosting the search form:

    http://website/custom-page/

    I have tried setting the search form action attribute like so:

    form action = ""

    but this creates the query:

    http://website/custom-page/?s=term-searched-for&members_search_submit=Search

    and the result is a 404 page not found.

    I have been reading in some places eg:
    here and here that buddypress redirects search queries so I need to override that redirection and I have attempted doing so without much success.

    My search form looks like this:

    	<div id="members-dir-search" class="dir-search bp-index-search" role="search">
                <?php //bp_custom_directory_members_search_form(); 
                $default_search_value = bp_get_search_default_text( 'members' );
                $search_value = !empty( $_REQUEST['s'] ) ? stripslashes( $_REQUEST['s'] ) : $default_search_value; ?>
    
                    <form action="" method="get" id="search-members-form">
                        <label><input type="text" name="s" id="members_search" placeholder="<?php echo esc_attr( $search_value ) ?>" /></label>
                        <input type="submit" id="members_search_submit" name="members_search_submit" value="<?php _e( 'Search', 'buddypress' ) ?>" />
                    </form>
    
    	</div>

    I check to see if the form has been submitted:

    <?php if(isset($_REQUEST ['members_search_submit'])){ ?>

    and then, following @Slave UA’s suggestion, I have copied and pasted the code from the “members-loop.php” file to my page template and I then changed

    bp_has_members( bp_ajax_querystring( 'members' )

    to

    bp_has_members(array('search_terms' => $search_term))

    If I hardcode the search term then it works but it does not seem to accept the search term submitted through the search form.

    Any help greatly appreciated.

    Avatar of Biswadip
    Biswadip
    Participant

    @biswadip

    In the above the line
    bp_has_members(array('search_terms' => $search_term))

    is actually
    bp_has_members(array('search_terms' => $search_value))

    Avatar of Biswadip
    Biswadip
    Participant

    @biswadip

    Thanks for your help it all works fine on Chrome and Firefox now – I was testing on IE8 as that is what our clients are using.

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

You must be logged in to reply to this topic.