Elementor custom query future events

mail@pastecode.io avatar
unknown
php
2 years ago
1.2 kB
35
Indexable
Never

//MR: Custom query for events CPT "termine" to only show events in the future (according to custom field "beginn_datum")
//Custom query ACTION for use of Elementor post widget
function upcomingTermineAction( $query ) {
	$today = date('Ymd');
	$query->set( 'post_type', 'termine' );
	$query->set( 'meta_query', array(
		array(
			'key' => 'beginn_datum',
			'value' => $today,
			'compare' => '>='
			, 'type' => 'DATE' )
		) 
	);
	$query->set( 'meta_key', 'beginn_datum' );
	$query->set( 'orderby', 'meta_value_num' );
	$query->set( 'order', 'ASC' );
}
add_action('elementor/query/upcoming_termine_action', 'upcomingTermineAction');


	
//MR: Custom query for events CPT "termine" to only show events in the future (according to custom field "beginn_datum")
//Custom query FILTER for use of Anywhere Elementor Post Adv widget
function upcomingTermine($query_args){
$query_args = array(
        'post_type' => 'termine',
        'meta_query' => array(
            array(
                'key' => 'beginn_datum',
                'value' => date('Ymd'),
				'compare'	=> '>='
            )
        )
     );
return $query_args;
}
add_filter('upcoming_termine_filter', 'upcomingTermine');