I followed this tutorial: https://docs.metabox.io/tutorials/show-upcoming-events-with-elementor/
The custom query is different in the video then the text shown, but I want the custom posts to sort by date.
Also my date format is different: d-m-Y
I came up with this query:
/* Filter Upcoming Event */
add_action('elementor/query/filter_events', function($query) {
$current_datetime = current_datetime()->format('d-m-Y');
$query->set('post_type', ['event']);
$meta_query = [
'Relations' => 'OR',
[
'key' => 'startdate',
'value' => date($current_datetime),
'compare' => '>=',
],
[
'key' => 'enddate',
'value' => date($current_datetime),
'compare' => '>=',
],
];
$query->set( 'meta_key', 'startdate' );
$query->set( 'orderby', 'meta_value' ); // for numeric meta use <code>meta_value_num</code> instead of <code>meta_value</code>
$query->set( 'order', 'ASC' );
$query->set('meta_query', $meta_query);
});
But the date sort is not working, not on frontend or de admin column startdate in the backend gives the same sort.
What is going wrong here?
Kind regards,
Ivan