[wp-hackers] Too Many Queries
Andy Mikester
andymikester at gmail.com
Wed Dec 6 01:30:54 GMT 2006
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.
Thanks
More information about the wp-hackers
mailing list