Home › Forums › Backend Issues (wp-admin) › Query by repeaterfield subfield(s)
Hi,
I am scratching my head if this is even possible. I have a CPT with a repeater field called “dates”. The repeater contains multiple fields but I’m only interested in the field “date” (value returns as ‘Ymd’).
On my archive page I wan’t to modify the main query to only output those posts that have a date that lies in the future. I can query the value of the first date with its index like so:
$query->set('meta_query',
array(
'relation' => 'AND',
array(
'key' => 'dates_0_date',
'value' => date('Ymd'),
'compare' => '<='
),
),
);
$query->set('meta_key', dates_0_date');
$query->set('orderby', 'meta_value');
$query->set('order','ASC');
But I have variable number of dates per post. So when I wan’t to query by the lowest “date” field that is still in the future I am completely lost.
I’ve tried to use a wildcard on the key like ‘dates%date’ but that doesn’t work.
Does anyone know if and how this is possible to achieve?
Thanks for any help or tips!
This is covered in the “4. Sub custom field values” section of this page.
Hi John, thanks for the link. I’ve looked at that page but didn’t realise my problem was covered there. I’ve managed to get it to work but honestly have no clue why/how it works.
Thanks again!
It has to do with changing the WHERE part of the query from something like
WHERE meta_key = "dates_0_date"
to
WHERE meta_key LIKE "dates_%_date"
OMG I was only focused on the key/value comparison and was wondering how I could compare two dates with “LIKE” … I am stupid!
Thanks again
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.