WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I thought the code below would work... but no dice. Something like "AND post_count > 0"

function contributors() { global $wpdb;

$authors = $wpdb->get_results("SELECT ID, user_nicename from $wpdb->users WHERE display_name <> 'admin' AND post_count > 0 ORDER BY display_name");

foreach ($authors as $author ) {

echo "<li>";
echo "<a href=\"".get_bloginfo('url')."/author/";
the_author_meta('user_nicename', $author->ID);
echo "/\">";
echo get_avatar($author->ID, 12);
echo "</a>";
echo "<a href=\"".get_bloginfo('url')."/author/";
the_author_meta('user_nicename', $author->ID);
echo "/\">";
the_author_meta('display_name', $author->ID);
echo "</a>";
echo "</li>";
share|improve this question
$args = array(
    'posts_per_page' => 1,
    'author'         => $author->ID
$posts = new WP_Query( $args );
$count = count( $posts );

Put this right after the foreach, $count will now contain either 1 or 0, put it through an if statement to filter the output.

share|improve this answer
Hmmm, thanks I tried that and put if ($count = "0") { around the output but nothing changed – Josh Jan 11 '12 at 23:31
try if( 0 < $count ) {, should do you fine. if( $count = 0 ) { just executes it if it's capable of setting the count to 0. At the very least you'll need ==, but that will only show authors with no posts, so you want $count > 0, but the better way to write this is 0 < $count (precisely because if you try to say 0 = $count, PHP will throw an error, so putting the value first became preferred, regardless of operator) – mor7ifer Jan 11 '12 at 23:43
Figured it out. I added the following function: $post_count = get_usernumposts($author->ID); And then add an if statement around the output like so: if($post_count > 0){ – Josh Jan 11 '12 at 23:44
Good to hear, don't forget to mark the solution for the next person having this problem :) – mor7ifer Jan 11 '12 at 23:48

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.