admin管理员组文章数量:1024158
I have a posts with a Ymd
date custom field. I would like the posts to be able to:
- Displays the posts where the date is not expired (lower than current date)
- Displays the posts that have the same Week Number as current day week number
I have achieved the first point by doing a meta_query
with the date custom field but I can't find any way to achieve the second point with the same custom field because it's a date rather than a week number.
This is my current code, or how I wanted it to be:
$args['meta_query'] = array(
'relation' => 'AND',
array(
'key' => 'date_held',
'value' => date('Ymd'),
'compare' => '>',
),
array(
'key' => date('W', 'date_held'),
'value' => date('W'),
'compare' => '=',
),
);
Is there any way I could achieve this without adding another custom field by modifying the current custom field date into week number then compare it within the WP_Query
argument?
Edit: Fixed the code to be like what I wanted
I have a posts with a Ymd
date custom field. I would like the posts to be able to:
- Displays the posts where the date is not expired (lower than current date)
- Displays the posts that have the same Week Number as current day week number
I have achieved the first point by doing a meta_query
with the date custom field but I can't find any way to achieve the second point with the same custom field because it's a date rather than a week number.
This is my current code, or how I wanted it to be:
$args['meta_query'] = array(
'relation' => 'AND',
array(
'key' => 'date_held',
'value' => date('Ymd'),
'compare' => '>',
),
array(
'key' => date('W', 'date_held'),
'value' => date('W'),
'compare' => '=',
),
);
Is there any way I could achieve this without adding another custom field by modifying the current custom field date into week number then compare it within the WP_Query
argument?
Edit: Fixed the code to be like what I wanted
本文标签: wp queryWPQuery on custom key and value
版权声明:本文标题:wp query - WP_Query on custom key and value 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745550895a2155627.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论