admin管理员组文章数量:1130349
I have been trying for hours, I don't get my query to work: display only posts (from custom post type) with a field (Advanced Custom Fields date picker) value that is more than today.
echo date('d-m-Y'); prints the same date format as the posts output the_field('datum_event'); : 06-01-2019
$args = array(
'post_type' => 'agenda',
'meta_query' => array(
array(
'key' => 'datum_event',
'value' => '06-01-2019',
'compare' => '>='
)
),
);
$loop = new WP_Query( $args );
What is missing?
I have been trying for hours, I don't get my query to work: display only posts (from custom post type) with a field (Advanced Custom Fields date picker) value that is more than today.
echo date('d-m-Y'); prints the same date format as the posts output the_field('datum_event'); : 06-01-2019
$args = array(
'post_type' => 'agenda',
'meta_query' => array(
array(
'key' => 'datum_event',
'value' => '06-01-2019',
'compare' => '>='
)
),
);
$loop = new WP_Query( $args );
What is missing?
Share Improve this question edited Jan 6, 2019 at 14:26 Krzysiek Dróżdż 25.6k9 gold badges53 silver badges74 bronze badges asked Jan 6, 2019 at 14:20 LudoLudo 612 silver badges11 bronze badges 1 |1 Answer
Reset to default 3What is missing? One tiny detail... And it's easy to overlook...
the_field('datum_event');
Prints the field using the format you've defined in field settings. But... It has nothing to do with how the value of that field is stored in DB. ACF uses YYYYMMDD format when storing date values in DB. And WP_Query doesn't use field format, since it looks directly in DB.
So you have to use other/raw format in your WP_Query:
$args = array(
'post_type' => 'agenda',
'meta_query' => array(
array(
'key' => 'datum_event',
'value' => '20190106',
'compare' => '>='
)
),
);
$loop = new WP_Query( $args );
I have been trying for hours, I don't get my query to work: display only posts (from custom post type) with a field (Advanced Custom Fields date picker) value that is more than today.
echo date('d-m-Y'); prints the same date format as the posts output the_field('datum_event'); : 06-01-2019
$args = array(
'post_type' => 'agenda',
'meta_query' => array(
array(
'key' => 'datum_event',
'value' => '06-01-2019',
'compare' => '>='
)
),
);
$loop = new WP_Query( $args );
What is missing?
I have been trying for hours, I don't get my query to work: display only posts (from custom post type) with a field (Advanced Custom Fields date picker) value that is more than today.
echo date('d-m-Y'); prints the same date format as the posts output the_field('datum_event'); : 06-01-2019
$args = array(
'post_type' => 'agenda',
'meta_query' => array(
array(
'key' => 'datum_event',
'value' => '06-01-2019',
'compare' => '>='
)
),
);
$loop = new WP_Query( $args );
What is missing?
Share Improve this question edited Jan 6, 2019 at 14:26 Krzysiek Dróżdż 25.6k9 gold badges53 silver badges74 bronze badges asked Jan 6, 2019 at 14:20 LudoLudo 612 silver badges11 bronze badges 1-
Try adding
'type' => 'DATE',to the most inner array – kero Commented Jan 6, 2019 at 14:27
1 Answer
Reset to default 3What is missing? One tiny detail... And it's easy to overlook...
the_field('datum_event');
Prints the field using the format you've defined in field settings. But... It has nothing to do with how the value of that field is stored in DB. ACF uses YYYYMMDD format when storing date values in DB. And WP_Query doesn't use field format, since it looks directly in DB.
So you have to use other/raw format in your WP_Query:
$args = array(
'post_type' => 'agenda',
'meta_query' => array(
array(
'key' => 'datum_event',
'value' => '20190106',
'compare' => '>='
)
),
);
$loop = new WP_Query( $args );
本文标签: wp queryWPQuery metaquery gt date
版权声明:本文标题:wp query - WP_Query meta_query >= date 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749039281a2306877.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


'type' => 'DATE',to the most inner array – kero Commented Jan 6, 2019 at 14:27