Support

Account

Home Forums Add-ons Repeater Field Display field from repeater if a number field has the highest value

Solved

Display field from repeater if a number field has the highest value

  • To better manage a site, I’m using an options page to centralize some options.

    I’m trying to create a shipping time option with an ACF repeater.

    I have three subfields..
    Shipping estimate – text field
    Category – taxonomy field where you can select multiple categories
    Priority – a number field to set priority.

    But for the front end I need a snippet to display the field.
    I want to display the shipping estimate on a product (only once) if the product has one of the selected categories. It could be some categories overlap with another row I created, if so I only want the shipping estimate with of the row that contains the highest priority number.

    Could someone help me along with the part to display the shipping estimate if one or more of the categories is selected and in has the highest priority number?

  • You will need to loop over the fields and find the one with the highest priority. For example:

    
    if (have_rows('your field', 'options')) {
      $estimate = '';
      $priority = -1; // or any value less than your lowest priority value
      while (have_rows('your field', 'options')) {
        the_row();
        if (your code to see if product is in selected category) {
          if (get_sub_field('priority') > $priority) {
            $priority = get_sub_field('priority');
            $estimate = get_sub_field('shipping_estimate');
          }
        }
      }
    }
    echo $estimate;
    
Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.