Display posts from today and future in Elementor 'posts widget'

According to Elementor documentation https://developers.elementor.com/custom-query-filter/#Multiple_Post_Types_in_Posts_Widget

I need to display future posts including the post from today. We want to display places and dates where a rock band will be (we don't want to display posts with date before today)

I am using this code:

add_action( 'elementor/query/my_custom_filter', function( $query ) {    
    $meta_query = $query-get( 'meta_query' );
    $meta_query[] = [       
        'post_status' = 'publish,future',
        'order' = 'ASC',
        'posts_per_page' = 3,
        'date_query' = array(
            array(
                'after' = date('Y-m-d'),
                'inclusive' = true,
            )
        ),    
    ];
    $query-set( 'meta_query', $meta_query );   
});

but it does not work.

How would you do it?

Topic filters query Wordpress

Category Web


Here is the working solution:

add_action( 'elementor/query/my-custom-query', function( $query ) {  

    $meta_query = $query->get( 'meta_query' );
$query->set( 'date_query', array(
    array(
            'after' => date('l, F jS, Y', strtotime('+0 day')),
        )
    ) ); 
} );

You can change the strtotime (+1 day....+n day ....-n day) to fetch the event's date you're looking for.

The date format here is ('l, F jS, Y'), you may change based on your WordPress setting (Dashboard >setting >General) Elementor query id: my-custom-query


Same problem here! Using a cpt "events", with a meta field "event_date", I need to sort by this meta date, but events without date yet, must be shown after.

I made this code, which let me order by date, but is showing events without date before.

add_action( 'elementor/query/my-custom-query', function( $query ) {
    $query->set( 'orderby', 'meta_value_num' );
    $query->set('order', 'ASC');
    $query->set( 'meta_key', 'eventdate' );
    
} );

Elementor Pro Post Widget doesn't allow filters :/

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.