If you want to filter the data by custom field posts, you should use meta_query
for this
Here is a working example:
$args = [
'post_type' => 'events',
'posts_per_page' => -1,
'orderby' => 'meta_value',
'meta_key' => 'event_date',
'order' => 'ASC',
'meta_query' => [
'relation' => 'AND',
[
'key' => 'event_date',
'value' => date('Y-m-d'),
'compare' => '>',
'type' => 'DATE'
],
],
];
$queryEvent = new WP_Query($args);
if ($queryEvent->have_posts()) :
while ($queryEvent->have_posts()) :
$queryEvent->the_post();
endwhile;
endif;
Hope this helps!
Related answer: fooobar.com/questions/1016413 / ...
source
share