Forums

[resolved] Post category count for specific year (4 posts)

  1. OllyA
    Member
    Posted 6 months ago #

    Was hopping someone could help me out? I want to display number of posts in a specific category for a specific year.

    A search of the forum produced this:

    <?php $count=0; $my_query = new WP_Query('cat=9&year=2011');
    while ($my_query->have_posts()) :
    $my_query->the_post();
    $count++; endwhile;
    echo $count; ?>

    But it displays an incorrect number of posts, thanks.

  2. keesiemeijer
    moderator
    Posted 6 months ago #

    Try it with this:

    <?php
    $my_query = new WP_Query('year=2011&posts_per_page=-1');
    $count = $my_query->post_count;
    echo 'post count='.$count;
    ?>
  3. OllyA
    Member
    Posted 6 months ago #

    Thats grate, thanks!

  4. keesiemeijer
    moderator
    Posted 6 months ago #

    No problem. Glad you got it resolved.

Reply

You must log in to post.

About this Topic

Tags