Posted By

yaysunshine on 05/12/11


Tagged

mysql php wordpress authors


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

srdjan


Wordpress Author Search Suggest


 / Published in: PHP
 

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.

  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  

You need to login to post a comment.