admin管理员组

文章数量:1310272

The goal is to display event-posts only for upcoming events. Setup is Elementor Pro combined with Astra Pro theme.

I added a custom date field called 'eventdatum' (d/m/Y) to posts and via the Elementor Pro Posts widget I want to show only posts where that certain date is today or in the future. If the field is empty I do not want the post to be shown.

Here is what I added to my functions.php:

add_action( 'elementor/query/upcoming_events', function( $query ) {

$today = date('d/m/Y');

  $query->set( 'post_type', 'post' );
  $query->set( 'meta_query', array( array( 'key' => 'eventdatum', 'value' => $today, 'compare' => '>=' , 'type' => 'DATE' ) ) );
  $query->set( 'meta_key', 'eventdatum' );
  $query->set( 'orderby', 'meta_value_num' );
  $query->set( 'order', 'ASC' );

} );

After I added the query ID to the Posts widget it still shows all posts ever created. All the posts that actually have the custom field 'event datum' filled out show at the end of the list (ordered ascending by the 'event datum' field).

What am I doing wrong?

本文标签: How do I correctly set up a WPQuery to only show upcoming eventposts