Based on what you’ve posted, I think you’re going for something like the code below. I’ve changed a number of things:
date()function isn’t used in that way. It converts an integer value of seconds into a string formatted date. If you already know the date, you can pass it as a string on its own like
compareto pass both dates at once
With all of that in mind, I think this should work:
$year = '2018'; // Build date range from year $date_range = array( $year . '-01-01', $year . '-12-31' ); $posts2018_args = array( 'post_type' => 'events', 'posts_per_page' => -1, // Sort by custom meta_key 'meta_key' => 'event_date', 'orderby' => 'meta_value_num', 'order' => 'ASC', // Filter by custom meta query 'meta_query' => array( 'relation' => 'AND', array( 'key' => 'event_category', 'value' => 'Indoor Track and Field', 'compare' => '=', ), array( 'key' => 'event_date', 'value' => $date_range, 'compare' => 'BETWEEN', 'type' => 'DATE', ), ), );
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
The ACF site is currently experiencing some issues.— Advanced Custom Fields (@wp_acf) September 29, 2022
We apologize for the inconvenience and we are working hard to get it back up and running as soon as possible.
© 2022 Advanced Custom Fields.