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:
‘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.
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?
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:
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.
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
station1 – 3 minutes
station2 – 5 minutes
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!
⏰ The Page Builder Summit 2020 starts today at 11:00 am (UK Timezone)!!— Advanced Custom Fields (@wp_acf) October 5, 2020
👉 Checkout the schedule for today’s presentations: https://t.co/B0H5J8m5S4
👨💻 Set a reminder for @elliotcondon talk on rapid block type development - Thursday morning 9:00amhttps://t.co/IjmnYP7rZi
© 2020 Advanced Custom Fields. Subscribe