Last active
February 8, 2024 14:29
-
-
Save aderaaij/6827478 to your computer and use it in GitHub Desktop.
Advanced Custom Fields datepicker: Show only events with a date of today or in the future. Extra comments from Pasnon @ ACF Forums: f you needed to, you could also play with the comparison date, which is the first array in meta_query, currently set to date("Y-m-d")
which is today; if you were to make it date("Y-m-d", strtotime("-1 day"))
you cou…
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 | |
/* | |
* Display posts only from today and in the future: | |
* http://old.support.advancedcustomfields.com/discussion/6000/how-to-sort-posts-by-acf-date-and-display-only-future-posts | |
* by Pasnon | |
*/ | |
$date_args = array( | |
'post_type' => 'events', | |
'meta_key' => 'event_start_date', | |
'posts_per_page' => -1, | |
'orderby' => 'meta_value_num', | |
'order' => 'ASC', | |
'meta_query'=> array( | |
array( | |
'key' => 'event_start_date', | |
'compare' => '>', | |
'value' => date("Y-m-d"), | |
'type' => 'DATE' | |
) | |
), | |
); | |
$date_query = new WP_Query( $date_args ); ?> | |
<?php | |
/* | |
* Display posts only from today or 30 days into the future: * | |
*/ | |
$date_args = array( | |
'post_type' => 'events', | |
'meta_key' => 'event_start_date', | |
'posts_per_page' => -1, | |
'orderby' => 'meta_value_num', | |
'order' => 'ASC', | |
'meta_query'=> array( | |
array( | |
'key' => 'event_start_date', | |
'compare' => '>', | |
'value' => date("Y-m-d"), | |
'type' => 'DATE' | |
), | |
array( | |
'key' => 'event_start_date', | |
'compare' => '<=', | |
'value' => date("Y-m-d", strtotime("+30 days")), | |
'type' => 'DATE' | |
) | |
), | |
); | |
$date_query = new WP_Query( $date_args ); | |
Hi There,
Thanks for you tips on how to do that, have another question i would like to be able to set weekly events using the plugin do you have any ideas on how to achieve that? Have been trying but cant find a way on how to do that.
That would be a life saver.
Thanks in advance,
That is slick! Mega props and thanks for the insight.
Hello. Just wanted to say this helped me out today. Thank you.
It is an excellent solution and it helped me so much!
👍 Thanks for the gist. Nice solution !
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is awesome. Thank you! Had been digging on a solution for this exact issue for a while and this finally worked. I threw this meta_query for the ACF datepicker field into pre_get_posts and it worked perfectly.