Wordpress Author Search Suggest


/ Published in: PHP
Save to your folder(s)

If your site also has registered users that aren't authors, you might have to modify this to cross-reference the usermeta table. Otherwise, this should work pretty well.


Copy this code and paste it in your HTML
  1. <?
  2. $term = $_GET['s'];
  3. $res = mysql_query("select * from wp_users where display_name like '%$term%'");
  4. if ($res) {
  5. ?>
  6. <p><strong>Were you looking for:</strong></p>
  7. <ul>
  8. <?
  9. while($author = mysql_fetch_assoc($res)) {
  10. $shortname = strtolower($author['user_login']);
  11. ?>
  12. <li><a href="<? bloginfo('home'); ?>/author/<? echo $shortname; ?>/"><? echo $author['display_name']; ?></a></li> <!-- may vary based on permalink structure -->
  13. <?
  14. }
  15. ?>
  16. </ul>
  17. <?
  18. }
  19. ?>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.