• Resolved five79horizons

    (@five79horizons)


    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
    Alberto

    add_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 );

Viewing 1 replies (of 1 total)
  • Thread Starter five79horizons

    (@five79horizons)

    Just for info,
    that’s the code to list events in starting date sort with Elementor Pro Post widget

    add_action( 'elementor_pro/posts/query/id_of_the_query', function( $query ){
    	$query->set('post_type', 'event');
    	$query->set('orderby', '_event_start_date');	
    	$query->set('meta_key', '_event_start_date');	 
    	$query->set('order', 'ASC');
    } );
Viewing 1 replies (of 1 total)

The topic ‘custom query Post widget sorting event date’ is closed to new replies.