Home › Forums › General Issues › Sort CPT with multiple dates › Reply To: Sort CPT with multiple dates
Okay, so if you have multiple datepicker fields on a Course, try something like this on your single-course.php to only show dates that are in the future:
$today = date( 'Y-m-d' );
if(get_field('date_1') > $today):
echo '<p>' . get_field('date_1') . '</p>';
endif;
if(get_field('date_2') > $today):
echo '<p>' . get_field('date_2') . '</p>';
endif;
etc...
Again, just make sure that the date format for $today matches what you specified in your datepicker field in the ACF settings. If that doesn’t work, you may need to do a php strtotime() with the dates.
Querying Courses by multiple ACF field dates would be a little trickery.
$today = date( 'Y-m-d' );
$args = array(
'post_type' => 'course',
'meta_query' => array(
'relation' => 'OR',
array(
'key' => 'date_1',
'value' => $today,
'compare' => '>',
),
array(
'key' => 'date_2',
'value' => $today,
'compare' => '>',
),
),
);
$query = new WP_Query( $args );
I just don’t think your can order a WP Query by multiple fields.
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!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.