Skip to:
Content
Pages
Categories
Search
Top
Bottom

Displaying the search term or phrase on member search

  • @henrywright-1

    Member

    Is there a function available to display the term or phrase the member has searched for?

Viewing 5 replies - 1 through 5 (of 5 total)
  • @henrywright-1

    Member

    OK i’ve come up with a solution but it feels dirty. Hoping someone can tell me if this approach is a bad one:

    In header.php just above my search form I have

    
    $standard_search_value = bp_get_search_default_text( 'members' );
    $query_value = !empty( $_REQUEST['s'] ) ? stripslashes( $_REQUEST['s'] ) : $standard_search_value;
    
    // globalise the search term or phrase variable so it can be used outside header.php
    $GLOBALS['search_term_phrase'] = $query_value;
    

    The in members-loop.php i can output the phrase when delivering results:

    echo $GLOBALS['search_term_phrase'];

    @shanebp

    Moderator

    $_REQUEST[‘s’] isn’t available in members-loop after clicking ?

    @henrywright-1

    Member

    @shanebp I thought that too but it seems to be. Check out how BP remembers the search term after clicking. See bp_directory_members_search_form() in bp-members-template.php

    @shanebp

    Moderator

    If it’s available, why assign it to a global in a different file ?

    The use of a global is the only thing funky about what you’re doing.

    Try just checking ‘s’ in members-loop.

    @henrywright-1

    Member

    echo $_REQUEST['s']; in members-loop.php worked! The global was the bit I didn’t like. For some reason I completely overlooked the obvious. Thanks @shanebp for the solution.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Displaying the search term or phrase on member search’ is closed to new replies.
Skip to toolbar