Last active
May 21, 2022 07:11
-
-
Save imagebox/c61b3c10d570ef5216928ebceadb6a44 to your computer and use it in GitHub Desktop.
[WordPress | Query Posts, Show Upcoming Events Posts By ACF Date] #WordPress #ACF
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
// not for the Events Calendar posts but for an Events CPT or sommething similar that uses ACF fields for dates. | |
// example from https://idelic.com/resource-type/events/ | |
<?php | |
$today = current_time('Ymd'); | |
$post_query_args = array( | |
'post_type' => 'resources', | |
'posts_per_page' => -1, | |
'status' => 'publish', | |
'tax_query' => array( | |
array ( | |
'taxonomy' => 'resource_type', | |
'field' => 'slug', | |
'terms' => 'events', | |
) | |
), | |
'meta_query' => array( | |
array( | |
'key' => 'event_start_date', | |
'compare' => '>=', // Upcoming Events - Greater than or equal to today | |
'value' => $today, | |
) | |
), | |
'meta_key' => 'event_start_date', | |
'orderby' => 'meta_value', | |
'order' => 'ASC', | |
); | |
$post_query = new WP_Query( $post_query_args ); | |
?> | |
<?php if ( $post_query->have_posts() ) : ?> | |
<?php while ( $post_query->have_posts() ) : $post_query->the_post(); ?> | |
<!-- your bullshit --> | |
<?php endwhile; ?> | |
<?php wp_reset_postdata(); ?> | |
<?php endif; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Line 40
is why I starred this gist.Thank you.