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

This is more of an efficiency question as the following code does do what I want.

$user_name = get_the_authour;
$query = new WP_Query('author_name=JustinH');
        $author_post_count = $query->post_count;

        if ($author_post_count >= jwh_option('post_count_set') {
            $post_status = 'publish';
            $post_status = 'pending';

That query pulls back all the user meta and all the data for their posts. Is there a more precise way to get to:

share|improve this question
up vote 2 down vote accepted

This thread on the wordpress codex shows how you can scope your SQL query:

$author_post_count = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE post_author = '" . $$username->ID . "' AND post_type = 'post' AND post_status = 'publish'");
share|improve this answer
Thanks. Exactlya what I wanted. – Justin W Hall Jun 13 '12 at 14:52

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.