Hi!
I created a member directory page that displays members of the site who have one of two specific roles. I want to create a search bar where users can search through that list for members by name.
Here is my search form code:
<form method="post" action="?go" id="searchform">
<input type="text" name="name">
<input type="submit" name="submit" value="Search">
</form>
Here is the search code I have so far:
<?php
if(isset($_POST['submit'])){
if(isset($_GET['go'])){
if(preg_match("/^[ a-zA-Z]+/", $_POST['name'])){
$name=$_POST['name'];
//-query the database table
$results = $wpdb->get_results( "SELECT <code>user_id</code> FROM <code>wp_usermeta</code> WHERE <code>meta_value</code> LIKE '%" . $name . "%'" );
//-create while loop and loop through result set
foreach($results as $result){
//-display the result of the array
echo $result->user_id;
}
}
else{
echo "<p>Please enter a search query</p>";
}
}
}
?>
I've tried a bunch of variations on this, but so far, all of my searches just go to the default "This is somewhat embarrassing, isn’t it?" page.
How do I achieve a working search bar?