我的脚本循环浏览我的 WordPress 网站上的帖子。
我还在计算未发布帖子的数量并将其存储在我的$i
变量中。
但是,由于这是循环多个结果,因此我需要$i
在每次迭代后将最终数字存储在一个唯一变量中。
我该如何处理?我可以$currentID
在任何阶段使用我的变量吗?
这是我的PHP片段供参考:
while ( $query->have_posts() ) : $query->the_post();
$currentID = get_the_ID();
while ( $events_list->have_posts() ) :
$events_list->the_post();
$postdate = get_the_date('Y-m-d');
$currentdate = date('Y-m-d');
if ($postdate > $currentdate) {
$i++;
}
endwhile;
// preferrably store the total of $i here in a unique variable then reset $i
the_content();
endwhile;
非常感谢任何指针:-)