admin管理员组文章数量:1334183
I've been trying to order these exhibitions based on the end_date custom field created with Advanced Custom Fields. I'm not able to properly get this working. I need the most recent dates first. I need to also only get posts with the exhibition_status
of past
. For the life of me I can't get this working and the below code is just the latest non working interation.
$args = array (
'post_type' => 'exhibitions',
'meta_query' => array(
'relation' => 'OR',
'query_one' => array(
'key' => 'exhibition_status',
'value' => 'past',
),
'query_two' => array(
'key' => 'end_date',
'compare' => '>=',
),
),
'orderby' => 'end_date',
'order' => 'ASC',
'post_status' => 'publish',
'posts_per_page' => 10,
'paged' => get_query_var( 'paged' ),
);
The date is based on this format F j, Y
How do I get all posts ordered by the ACF field end_date
and only get posts where the ACF field exhibition_status
equals past
?
I've been trying to order these exhibitions based on the end_date custom field created with Advanced Custom Fields. I'm not able to properly get this working. I need the most recent dates first. I need to also only get posts with the exhibition_status
of past
. For the life of me I can't get this working and the below code is just the latest non working interation.
$args = array (
'post_type' => 'exhibitions',
'meta_query' => array(
'relation' => 'OR',
'query_one' => array(
'key' => 'exhibition_status',
'value' => 'past',
),
'query_two' => array(
'key' => 'end_date',
'compare' => '>=',
),
),
'orderby' => 'end_date',
'order' => 'ASC',
'post_status' => 'publish',
'posts_per_page' => 10,
'paged' => get_query_var( 'paged' ),
);
The date is based on this format F j, Y
How do I get all posts ordered by the ACF field end_date
and only get posts where the ACF field exhibition_status
equals past
?
1 Answer
Reset to default 1I've modified your existing code.Can you please try the code bellow:
$args = array (
'post_type' => 'exhibitions',
'meta_query'=> array(
'relation' => 'AND',
array(
'key' => 'exhibition_status',
'value' => 'past',
),
array(
'key' => 'end_date',
'compare' => 'EXISTS',
'type' => 'DATE'
),
),
'meta_key' => 'end_date',
'orderby' => 'meta_value',
'order' => 'ASC',
'post_status' => 'publish',
'posts_per_page' => 10,
'paged' => get_query_var( 'paged' ),
);
本文标签: wp queryACF Date Based wpquery
版权声明:本文标题:wp query - ACF Date Based wp_query 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742297282a2448988.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
'meta_key' => 'end_date'
and set the'order_by' => 'meta_value'
. – Shazzad Commented Jul 2, 2020 at 16:37'relation' => 'OR'
should be'relation' => 'AND'
– Shazzad Commented Jul 2, 2020 at 16:54