Forums

[resolved] Post Count For Certain Year (3 posts)

  1. thisisedie
    Member
    Posted 11 months ago #

    I want to get the post count for a certain year. I've tried doing different things with this code

    <?php
    $count_posts = wp_count_posts();
    echo $count_posts->publish;
    ?>

    but none work. Can anyone tell me how I can do this?

  2. MichaelH
    moderator
    Posted 11 months ago #

    Could use wpdb on the wp_posts table but this seems easier:

    <?php
    $count=0;
    $my_query = new WP_Query('year=2008');
    while ($my_query->have_posts()) : $my_query->the_post();
    $count++;
    endwhile;
    echo '2008 post count is ' . $count;
    ?>
  3. thisisedie
    Member
    Posted 11 months ago #

    Thanks muchly :)

Reply

You must log in to post.

About this Topic

Tags

No tags yet.