Hello
I am stuck with the issue:
I have a loop section in my websites, where I want to show events. Elementor/Wordpress shows all post related on the publishing date. But I want to show the posts with the event-date (‘datum’). And only from today onwards. How can I manage that?
I tried also with the code:
function my_pre_get_posts( $query ) {
// do not modify queries in the admin
if ( is_admin() ) {
return $query;
}
// only modify queries for the main loop
if ( $query->is_main_query() ) {
// only modify queries on the events archive page
if ( is_post_type_archive( ‘events’ ) ) {
// Set meta query to filter by ‘datum’ field
$today = date( ‘Ymd’ ); // Format: YYYYMMDD
$meta_query = array(
array(
‘key’ => ‘datum’, // Replace with your ACF field name
‘value’ => $today,
‘compare’ => ‘>=’,
‘type’ => ‘DATE’,
),
);
$query->set( ‘post_type’, ‘events’ );
$query->set( ‘orderby’, ‘meta_value’ );
$query->set( ‘meta_key’, ‘datum’ ); // Replace with your ACF field name
$query->set( ‘order’, ‘ASC’ ); // Order: oldest date first
$query->set( ‘meta_query’, $meta_query );
}
}
// return
return $query;
}
add_action( ‘pre_get_posts’, ‘my_pre_get_posts’ );