Support

Account

Home Forums ACF PRO WP_Query repeater field minimum value

Solving

WP_Query repeater field minimum value

    • Flegma

    • October 17, 2015 at 12:13 am

    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!

    • Flegma

    • October 17, 2015 at 7:43 pm

    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.

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.

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.