Support

Account

Home Forums Add-ons Repeater Field Get minimum value from ACF Repeater

Solved

Get minimum value from ACF Repeater

  • Hello

    ACF is great plugin for WP. I have a small question regarding the ACF Repeater.
    I am using a CPT, from ACF custom fields, I have created taxonomy and a text field. Please check the screenshot:
    ACF

    <?php $args = array( 'post_type' => 'fares', 'posts_per_page' => 8 );
    			$the_query = new WP_Query( $args );
    			if ( $the_query->have_posts() ) { while ( $the_query->have_posts() ) {
          $the_query->the_post(); ?>
    
    				<div class="test">
    					<?php the_title(); ?> <br>
    					<?php if( have_rows('fares_from') ): while ( have_rows('fares_from') ) : the_row(); ?>
    						<?php $term = get_sub_field('fares_from_taxonomy'); ?>
    						<pre> <?php //print_r($term); ?> </pre>
    	        <span><?php echo $term->name; ?></span>
    	        <span><?php echo get_sub_field('fare_price'); ?></span>
    	    		<?php endwhile; endif; ?>
    	    		<hr>
    				</div>
    
          <?php } // end while
    } // endif
    // Reset Post Data
    wp_reset_postdata(); ?>

    Here is my code, which is pulling the title of the post and all ACF repeater fields, but here I really want only the lowest value field only.
    The data I want is:
    title of the post, Taxonomy term with the lowest value.

    Could you please help?

    Thank you

  • 
    if (have_rows('fares_from')) {
      $term = false;
      $fare_price = false;
      while (have_rows('fares_from')) {
        the_row();
        if ($fare_price === false || get_sub_field('fare_price') < $fare_price) {
          $fare_price = get_sub_field('fare_price');
          $term = get_sub_field('fares_from_taxonomy');
        }
      } // end while have rows
      if ($term)  {
        ?>
          <span><?php echo $term->name; ?></span>
          <span><?php echo $fare_price; ?></span>
        <?php 
      }
    } // end if have rows
    
  • Thank you John, that solved it.

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

The topic ‘Get minimum value from ACF Repeater’ is closed to new replies.