Forums

wp_count_posts (4 posts)

  1. thetvstop
    Member
    Posted 1 year ago #

    How do I use wp_count_posts outside of the loop?

  2. alchymyth
    The Sweeper
    Posted 1 year ago #

    wp_count_posts() does not seem to be loop dependant:
    if the docu does not answer your question,
    http://codex.wordpress.org/Function_Reference/wp_count_posts

    you may need to describe in more detail where you want to use this.

    (btw: the examples in the docu assign the results to variables; if you want to output the results, you would need to use the echo command.)

  3. thetvstop
    Member
    Posted 1 year ago #

    http://www.thetvstop.com/watch/ if you look at the TOP TV SHOWS, section on top you will see how I am trying to display post counts.

    For some reason the default <?php count_posts(); ?> works to count the total number of posts.

    However, the <?php count_posts('pages'); ?> function does not work. Any clues?

  4. alchymyth
    The Sweeper
    Posted 1 year ago #

    However, the <?php count_posts('pages'); ?> function does not work.

    maybe because it does not exist?
    have you read the docu?

    if you want to show the number of published pages, try:

    <?php
    $count_pages = wp_count_posts('page');
    echo $count_pages->publish;
    ?>

Topic Closed

This topic has been closed to new replies.

About this Topic