Free Thinking.

The latest.

  1. Making users searchable in Wordpress

    Posted 2 weeks, 6 days ago and tagged as ,

    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.

    1 Comment

Previous posts.

  1. The Big Picture breaks a record

    Posted 2 months, 3 weeks ago and tagged as ,

    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…

    No Comments

  2. Come chat about Social Media…

    Posted 3 months, 4 weeks ago and tagged as ,

    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…

    No Comments

  3. That was the Wordcamp that was…

    Posted 4 months ago and tagged as ,

    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,…

    5 Comments