Return to Snippet

Revision: 46059
at May 12, 2011 06:37 by yaysunshine


Updated Code
<?
    $term = $_GET['s'];
    $res = mysql_query("select * from wp_users where display_name like '%$term%'");
    if ($res) {
    	?>
    	<p><strong>Were you looking for:</strong></p>
    	<ul>
    	<?
    	while($author = mysql_fetch_assoc($res)) {
    		$shortname = strtolower($author['user_login']);
    		?>
    		<li><a href="<? bloginfo('home'); ?>/author/<? echo $shortname; ?>/"><? echo $author['display_name']; ?></a></li> <!-- may vary based on permalink structure -->
    		<?
    	}
    	?>
    	</ul>
    	<?
    }
?>

Revision: 46058
at May 12, 2011 06:36 by yaysunshine


Initial Code
<?
    		$term = $_GET['s'];
    		$res = mysql_query("select * from wp_users where display_name like '%$term%'");
    		if ($res) {
    			?>
    			<p><strong>Were you looking for:</strong></p>
    			<ul>
    			<?
    			while($author = mysql_fetch_assoc($res)) {
    				$shortname = strtolower($author['user_login']);
    				?>
    				<li><a href="<? bloginfo('home'); ?>/author/<? echo $shortname; ?>/"><? echo $author['display_name']; ?></a></li> <!-- may vary based on permalink structure -->
    				<?
    			}
    			?>
    			</ul>
    			<?
    		}
    		?>

Initial URL

                                

Initial Description
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.

Initial Title
Wordpress Author Search Suggest

Initial Tags
mysql, php, wordpress

Initial Language
PHP