Created
February 15, 2021 20:00
-
-
Save askwpgirl/5caa4f2b090a117b9d3285ecb724ae05 to your computer and use it in GitHub Desktop.
Show Elementor Posts after today's date for events using ACF date field
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//Info about custom query filters: | |
//https://developers.elementor.com/custom-query-filter/ combined with | |
// https://www.advancedcustomfields.com/resources/date-time-picker/ | |
// The query ID goes in the Elementor Query under the Query area of the post list widget (see screenshot). | |
// The function below goes in your child theme's functions.php file or use the Code Snippets plugin to add it. | |
/*-------------------------------------------------------*/ | |
/* Show Event posts in date order and remove past dates | |
/*-------------------------------------------------------*/ | |
add_action( 'elementor/query/event_filter', function( $query ) { | |
$today = date('Y-m-d'); | |
$query->set( 'meta_query', array( | |
array( | |
'key' => 'event_date', | |
'compare' => '>', | |
'value' => $today, | |
'type' => 'DATE', | |
) | |
) ); | |
$query->set('orderby', 'meta_value'); | |
$query->set('order', 'ASC'); | |
$query->set('meta_key', 'event_date'); | |
} ); |
@kpfdigital Thanks for your notes!
@askwpgirl Thanks for your initial code!
I also changed the > to >= and it worked how I wanted it to.
From: 'compare' => '>',
To: 'compare' => '>=',
Thank you!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Been busting my head creating a query like that. Love it, thank you so much. I was able to easily adapt it to show only events that have passed.