Home › Forums › Add-ons › Repeater Field › Query on a repeater date pear (acf)
I’m struggling with this. I a have list of date (not fixed, I can have as many date as I want) made thanks to the ACF Repeater. In my query, I want to filter by date.
But, I have to hide some post if the date choosen is not between my 2 date fields (evenement_date_start and evenement_date_end). This is an example of my date list.
So if I choose between 01/10/2020 and 20/10/2020, the event should not show up. But right now, it does and I can’t figure out why.
This is my query args, my date and variable have this format “Ymd” :
$args[] =
['relation' => 'OR',
['relation' => 'AND',
[
"key" => "evenements_liste_dates_AAA_evenement_date_start",
"compare" => "<=",
"type" => 'DATE',
"value" => $startDate,
],
[
"key" => "evenements_liste_dates_AAA_evenement_date_end",
"compare" => ">=",
"type" => 'DATE',
"value" => $endDate,
]
],
['relation' => 'OR',
[
"key" => "evenements_liste_dates_AAA_evenement_date_start",
"compare" => "BETWEEN",
"type" => 'DATE',
"value" => [$startDate, $endDate],
],
[
"key" => "evenements_liste_dates_AAA_evenement_date_end",
"compare" => "BETWEEN",
"type" => 'DATE',
"value" => [$startDate, $endDate],
]
],
];
And my post where rewriting
add_filter('posts_where', function ($query, WP_Query $wp_query) {
if(!is_admin() && $wp_query->query_vars['post_type'] == "evenement" && !$wp_query->is_main_query()) {
$query = str_replace("meta_key = 'evenements_liste_dates_AAA_evenement_date_start'", "meta_key LIKE 'evenements_liste_dates_%_evenement_date_start'", $query);
$query = str_replace("meta_key = 'evenements_liste_dates_AAA_evenement_date_end'", "meta_key LIKE 'evenements_liste_dates_%_evenement_date_end'", $query);
}
return $query;
}, 10, 2);
date fields do not store values in standard date format and should not be considered date’s for query purposes
You’re type must be ‘CHAR’ or ‘NUMERIC’ default is fine
your date values must be formated YYYYMMDD
You must be logged in to reply to this topic.
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.