Search code examples
phphtmlwordpressbuddypress

HTML select value to PHP bp_has_members( 'search_terms=??)


trying to pass the values of a select option to change the search term of members in Bp.

so far I can print the value with "echo" but i cannot set the search term depending on my option selected.

Printing the option works fine:

<form method="post">
<select name="category">
  <option value="" selected>All</option>
  <option value="Design and print">Design and Print</option>
  <option value="Food & Drink">Food &amp Drink</option>
  <option value="market">Market</option>
    </select>
    <button type="submit" value="execute">SEARCH</button>     
</form>

<h5><?php echo $_POST['category']; ?></h5>

When I want to send the value as a string in the search term I cannot figure out the right code.

here what I have:

<?php if ( bp_has_members( 'search_terms=$_POST['category']') ) : ?>        
<?php while ( bp_members() ) : bp_the_member(); ?> 

however, the search not work as if i write 'search_terms=Food & Drink' for example


Solution

  • change this

    bp_has_members( 'search_terms=$_POST['category']')
    

    to

    bp_has_members("search_terms={$_POST['category']}")
    

    You should have been getting a syntax error. try turning error reporting on and debugging your code next time.