• I am currently using this code to query specific posts by month and year in
    a page template, so I have to repeat this query 12 times for every year
    everytime the page is loaded:

    <?php query_posts('cat=2&year=2006&monthnum=1');
    if ($wp_query->post_count >= 1)
    {
    ?>
    <---do stuff-->
    <?php
    }
    ?>

    I am worried that this is too many queries. Is there a better way of doing
    this? Perhaps something along these lines:

    <?php query_posts('cat=2&year=2006');
    if ($wp_query->month_num = 1) && ($wp_query->post_count >= 1)
    {
    ?>
    <---do stuff-->
    <?php
    }
    ?>

    I know month_num won’t work but is there any way of getting the month number so I can pass it in the PHP if statement? That way I only have to run one query for each year.

    Thanks

Viewing 2 replies - 1 through 2 (of 2 total)
  • You have to build a new sql-query like

    SELECT COUNT(*), year, month FROM texte GROUP BY year, month

    which returns an array with count, year and month in just one query

    Thread Starter andymike

    (@andymike)

    Thanks muelheim,

    Could you explain a little bit further how to build the sql-query?

    I appreciate your help.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Too Many Queries’ is closed to new replies.