Hello,
i have a question about WP_Query for ACF’s Repeater sub-field value.
Right now the query works but the results are any post that containt a value in its repeater’s sub-field.
I want to query the minimal value in those sub-fields.
This is the code i have:
array(
‘key’ => ‘single_villa_prices_%_price’,
‘value’ => array($price_min,$price_max),
‘compare’ => ‘BETWEEN’,
)
It returns any villa that have a value from price_min to price_max in any row of sub-fields. Is there a way i can make it query minimal value from those sub-field values?
Thanks in advance.
*edit*
Is there a way i can sort the values in all posts so that then i could query only single_villa_prices_0_price perhaps?
Hi @flegma
You should be able to query by minimal value like
array(
'key' => 'single_villa_prices_%_price',
'value' => $price_min,
'compare’'=> '>',
)
if you only want to query a specific rows meta you can simply do:
array(
'key' => 'single_villa_prices_0_price',
'value' => $price_min,
'compare’'=> '>',
)
and ignore the posts_where filters.
Best of luck!
Its not working that way, i dont know why.
In ACF i have Repeater Field (single_villa_prices) and there are 4 values in each row (start_date, end_date, price, min_stay).
My query is this for now:
http://pastebin.com/rt1TFxap
Even if i use < or > you suggested its not returning anything. If i check the query, it looks right, but its not (apparently).
I even tried value ‘100’ (without passing the variable, just pure string) and its not working either.
Dear Colleagues,
I came across the neccessity of the same feature.
I’ve Property CPT which has a repeater field Proximity2Metro. Inside that repeater are subfields Minutes and Station. Minutes field contains how much minutes does it take to get to/from the corresponding metro station to/from the property.
Let’s say I’ve the following
property 1:
station1 – 3 minutes
station2 – 5 minutes
property 2:
station3 – 4 minutes
station4 – 6 minutes
Then I need to filter properties by the minimum number of minutes. For example, I need all the properties with no more than 3 minutes from metro.
For now I have to add filtering inside while-have-posts loop, which is not very efficient. It should be accomplished via wp_query args.
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’re hard at work on ACF 6.1, and Beta 1 is now available 🚀
— Advanced Custom Fields (@wp_acf) March 16, 2023
This release includes custom post type and taxonomy registration, an improved experience when selecting field types, PHP 8.1 and 8.2 compatibility, and more!
Let’s take a look 🧵https://t.co/Y0WcAT11l4
© 2023 Advanced Custom Fields.
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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.