ElementorWordPress

Filter Elementor Post Widgets by date of an ACF field

Josselyn Jayant
10 November 2026
Lecture : 2 min
Updated 6 November 2026

For a customer requirement I had to display the posts via the Elementor Post widget in ascending date and time order. The time and date field is managed via a date and time picker in ACF, because posts are created via ACF.

Here is the code to add to your functions.php. The highlighted lines can be modified as desired.
You will also need to modify the server filtering field in the Elementor widget in order to filter with the function you have just created.

In my case, the ACF field is called date_and_time, I display it in a DESC manner and line 17 I generate the name of the query (which I will note in the elementor widget)

				
					function filter_posts_by_acf_date( $query ) {
    // Vérifiez que la meta_key 'date_et_heure' existe
    $meta_query = array(
        array(
            'key' => 'date_et_heure',
            'compare' => 'EXISTS',  
        ),
    );

    $query->set( 'meta_key', 'date_et_heure' );
    $query->set( 'orderby', 'meta_value' );
    $query->set( 'order', 'DESC' ); // Pour un ordre décroissant. Utilisez 'ASC' pour un ordre croissant.
    $query->set( 'meta_query', $meta_query );
}

// Remplacez 'filtrage_date' par l'ID de votre requête personnalisée que vous avez défini dans l'widget Elementor
add_action( 'elementor/query/filtrage_date', 'filter_posts_by_acf_date' );

				
			

Compatibility and limits

  • Elementor Pro: Posts widget and Loop Grid, in Query > Query ID.
  • ACF Date Picker and Date Time Picker fields: their stored formats (Ymd and Y-m-d H:i:s) sort correctly as text.
  • Only posts with a value in the field are displayed (EXISTS condition). To hide past events, add a comparison with today’s date to the meta query.
Before you start

Back up your site before changing any code, and test on a staging copy first.

Need help adding it?

I can take care of it, or adapt it to your store.

Read also

Elementor · WooCommerce

Stock Status Widget for Elementor

Elementor · Plugins

Back to Top for Elementor

Elementor · Plugins · WooCommerce

WooCommerce Gallery Hover for Elementor Loop