Title: custom query Post widget sorting event date
Last modified: February 1, 2019

---

# custom query Post widget sorting event date

 *  Resolved [five79horizons](https://wordpress.org/support/users/five79horizons/)
 * (@five79horizons)
 * [7 years, 3 months ago](https://wordpress.org/support/topic/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
    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](https://wordpress.org/support/users/five79horizons/)
 * (@five79horizons)
 * [7 years, 3 months ago](https://wordpress.org/support/topic/custom-query-post-widget-sorting-event-date/#post-11168158)
 * 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.

 * ![](https://ps.w.org/events-manager/assets/icon-256x256.png?rev=1039078)
 * [Events Manager - Calendar, Bookings, Tickets, and more!](https://wordpress.org/plugins/events-manager/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/events-manager/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/events-manager/)
 * [Active Topics](https://wordpress.org/support/plugin/events-manager/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/events-manager/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/events-manager/reviews/)

 * 1 reply
 * 1 participant
 * Last reply from: [five79horizons](https://wordpress.org/support/users/five79horizons/)
 * Last activity: [7 years, 3 months ago](https://wordpress.org/support/topic/custom-query-post-widget-sorting-event-date/#post-11168158)
 * Status: resolved