For a soon-to-be launching client project I needed the Wordpress built in search to return, not just post and page content, but also users that match the users query string. I couldn’t find a plugin that facilitated this so put together the following code snippet to handle it:
<?
$authors = $wpdb->get_results('SELECT * FROM '.$wpdb->users.' WHERE user_login LIKE "%'.urldecode($_GET['s']).'%"');
if(!empty($authors)){
?>
<h2>Authors matching your query</h2>
<?
foreach($authors as $author){
$bio = $wpdb->get_results('SELECT * FROM '.$wpdb->usermeta.' WHERE user_id="'.$author->ID.'" AND meta_key="description"');
$bio = $bio[0]->meta_value;
?>
<div class="search-result">
<h3><?=$author->user_login?></h2>
<?=apply_filters('the_content', $bio)?>
</div>
<?
}
?>
All I’m doing with this is querying the user table to match any users that contain the search query in their login name and then looping through the results. Inside the loop I’m also looking up the author’s description - annoyingly this is stored in a separate table (”usermeta”) and then related to the entry via ID.
The Big Picture, a project I've been involved with along with Stef since the beginning of the year, finally came to fruition on Saturday with…
This Wednesday (July 30th) the GMG's bringing Skillswap back to the Shire, now branded as "Tecchie Laptop Sessions". The first of the events (which…
I made it back from the wild lights of Birmingham after a pretty epic Wordcamp. While I found a few of the presentations slightly lackluster,…