admin管理员组文章数量:1287581
I'm trying to output all Sundays between 2 different dates (startdate and enddate). The following PHP code made this work pefectly. But how to get these dates by the WP_Query?
PHP example (works):
$startDate = new DateTime('2021-08-01');
$endDate = new DateTime('2021-08-31');
$sundays = array();
while ($startDate <= $endDate) {
if ($startDate->format('w') == 0) {
$sundays[] = $startDate->format('Y-m-d');
}
$startDate->modify('+1 day');
}
foreach($sundays as $sundayItem) {
echo $sundayItem.'<br>';
}
The above code outputs the following:
2021-08-01
2021-08-08
2021-08-15
2021-08-22
2021-08-29
What I am trying in the WP_Query:
$agenda_query = new WP_Query(array(
'post_type' => 'mm_agenda',
'posts_per_page' => -1,
'meta_key' => 'agenda_startdate',
'orderby' => 'agenda_startdate',
'order' => 'ASC',
'meta_query' => array(
array(
'key' => 'agenda_startdate',
'value' => '2021-08-01',
'compare' => '>'
),
array(
'key' => 'agenda_enddate',
'value' => '2021-08-31',
'compare' => '<'
),
),
));
Does anyone has the answer, to get this work? How to integrate that Sunday within the wp_query? And let the foreach outputs the same as the regular PHP method. Thanks a lot in advance.
本文标签: wp queryHow to wpquery every Sunday between a startdate and enddate
版权声明:本文标题:wp query - How to wp_query every Sunday between a startdate and enddate? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741304574a2371290.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论