Forums

Show Total Posts (2 posts)

  1. JSauce16
    Member
    Posted 1 year ago #

    Hello,

    I want to show the total number of posts in my database.

    I found this:

    <?php
    $count_posts = wp_count_posts();
    ?>

    But it doesn't seem to show anything. How can I, simply, without a plugin, show the number of posts in the database?

    Thanks,

    Jon

  2. richarduk
    Member
    Posted 1 year ago #

    <?php
    $count_posts = wp_count_posts();
    $published_posts = $count_posts->publish;
    echo '<h1>There are '   .  $published_posts  .  ' published posts</h1>' ;
    ?>

    That shows published posts. Not sure how you show total number of posts e.g. drafts as well unless do that separately and then add them up

    http://codex.wordpress.org/Function_Reference/wp_count_posts

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.