【发布时间】:2014-04-01 15:08:11
【问题描述】:
如果没有与查询匹配的帖子,我想更改 WP_query 参数。 具体来说,我想更改月份值,如果当前月份没有任何帖子可显示,我想使用新的月份值再次运行查询。
$query = new WP_Query (array('category_name'=> $cat,'year' => $ano, 'monthnum' => $monthnum, 'posts_per_page' => $posts_per_page, 'post__not_in' => array($id)));
if ($query->have_posts()) : ?>
while ($query->have_posts()) : $query->the_post();
//do something
endwhile;
else:
$monthnum = $monthnum - 1;
if($monthnum == 0){
$monthnum = 12;
}
/*
here I want to run the query again with the new $monthnum value
*/
endif;
wp_reset_query();
你知道解决办法吗?请帮帮我!谢谢。
【问题讨论】:
-
如果我理解正确,这不仅仅是一个替代查询,如果没有找到帖子,你想继续将月份 val 减少 1 直到找到帖子?