Home › Forums › General Issues › Issue with query between 2 dates › Reply To: Issue with query between 2 dates
This depends on what you’re looking for exactly.
Do you have a range of dates that the start and end date of the event needs to be between? Do you have a date and anything after that date is shown? These would be completely different queries.
For example, if I wanted all of the events with start or end dates after today, then I wouldn’t check the start date at all because if the end date is after today then the start date does not matter
'meta_query' => array(
array(
'key' => 'end_date',
'compare' => '>=',
'value' => $today,
)
)
But if I want events that are happening between two dates
'meta_query' => array(
'relation' => 'OR',
array(
array(
'relation' => 'AND',
array(
'key' => 'start_date',
'compare' => '>=',
'value' => $start_range
),
array(
'key' => 'start_date',
'compare' => '<=',
'value' => $end_range
)
)
),
array(
array(
'relation' => 'AND',
array(
'key' => 'end_date',
'compare' => '>=',
'value' => $start_range
),
array(
'key' => 'end_date',
'compare' => '<=',
'value' => $end_range
)
)
)
)
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.