custom query Post widget sorting event date
-
Hello everyone,
I would like to list in Elementor Pro Post widget the events in starting date sort.Surfing on the web I understood that I should write in functions.php of my theme a new function to be able to sort posts by starting date.
I found this script and I suppose to be the right way to do it..it doesn’t works maybe because there aren’t the right values in “post_end_date”…
some help is really appreciated.
Kind regards
Albertoadd_action( ‘elementor_pro/posts/query/test’, function ( $wp_query, $posts_widget ) {
$expire = get_field( ‘post_end_date’ ) ? : date( ‘Ymd’ );
$wp_query->set( ‘meta_query’, [
‘relation’ => ‘OR’,
[
‘key’ => ‘post_end_date’,
‘value’ => $expire,
‘compare’ => ‘>=’,
‘type’ => ‘NUMERIC’,
],
[
‘key’ => ‘post_end_date’,
‘compare’ => ‘NOT EXISTS’,
],
]);
}, 10 ,2 );
The topic ‘custom query Post widget sorting event date’ is closed to new replies.