WordPress.org

Ready to get started?Download WordPress

Forums

the_author_posts(); not counting custom post types (3 posts)

  1. Frozen Angel
    Member
    Posted 4 years ago #

    Hi there,

    I've noted that the_author_posts(); template tag didn't count the custom post types. Just "regular posts" are being counted!

    Is there a way to fix this and count everything written by the authors on my blog?

    Regards!

  2. MichaelH
    Member
    Posted 4 years ago #

    <?php
    $post_author = 1; //author id
    $count = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->posts WHERE post_author = $post_author AND post_type IN ('post','page','book') and post_status = 'publish'" );
    echo 'count of post types post,page,book for user id 1: '.$count
    ?>
  3. Frozen Angel
    Member
    Posted 4 years ago #

    MichaelH thanks for your help.

    Can you just tell me how to use that code without have to define the author ID? I mean... it's a multiauthor blog, so it should retrieve the post count of the specific author of the post, which obviously is not always the same one.

    Again, thanks for your help!

Topic Closed

This topic has been closed to new replies.

About this Topic