Skip to:
Content
Pages
Categories
Search
Top
Bottom

Displaying the search term or phrase on member search

  • Avatar of Henry
    Henry
    Participant

    @henrywright-1

    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)
  • Avatar of Henry
    Henry
    Participant

    @henrywright-1

    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'];

    Avatar of shanebp
    shanebp
    Moderator

    @shanebp

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

    Avatar of Henry
    Henry
    Participant

    @henrywright-1

    @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

    Avatar of shanebp
    shanebp
    Moderator

    @shanebp

    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.

    Avatar of Henry
    Henry
    Participant

    @henrywright-1

    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)

You must be logged in to reply to this topic.