WordPress.org

Support

Support » How-To and Troubleshooting » Count posts of an specific author in Author.php

Count posts of an specific author in Author.php

Viewing 2 replies - 1 through 2 (of 2 total)
  • Try this in your author template:

    <?php
    global $wp_query;
    $curauth = $wp_query->get_queried_object();
    $post_count = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE post_author = '" . $curauth->ID . "' AND post_type = 'post' AND post_status = 'publish'");
    ?>
    <h2>Post Count: <?php echo $post_count; ?></h2>

    Amazing, it worked!!

    It’d actually work too for the archive.php page, counting posts for one single category? I asume I should change some of the variables, but i don’t know which one…

    Thanks Michael!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Count posts of an specific author in Author.php’ is closed to new replies.