WordPress.org

Ready to get started?Download WordPress

Forums

Count posts of an specific author in Author.php (3 posts)

  1. further
    Member
    Posted 5 years ago #

    Hello,

    I'd like to show the total number of posts writen by an specific author on it's author.php page, like this:

    http://www.bebesymas.com/autor/lola-rovati

    any ideas?

    thanks!

  2. MichaelH
    Member
    Posted 5 years ago #

    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>
  3. further
    Member
    Posted 5 years ago #

    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!

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.