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
版权声明:本文标题:How do I correctly set up a WP-Query to only show upcoming event-posts? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741809467a2398705.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论