Support

Account

Home Forums Add-ons Repeater Field Repeater Sub Field Values In Array

Solved

Repeater Sub Field Values In Array

  • Hi

    I am currently outputting repeater subfield values in a hidden form field value via the following if statement

    if( have_rows('a5_digital_120gsm_uncoated') ):
    				
    			   echo '<input type="hidden" id="a5120gsm8pp" name="a5120gsm8pp" value="';
    			    while ( have_rows('a5_digital_120gsm_uncoated') ) : the_row(); // loop through the rows of data
    			        echo the_sub_field('8pp').'!';  // display a sub field value
    			    endwhile;
    				echo '">';
    				echo '<input type="hidden" id="a5120gsm12pp" name="a5120gsm12pp" value="';
    			    while ( have_rows('a5_digital_120gsm_uncoated') ) : the_row(); // loop through the rows of data
    			        echo the_sub_field('12pp').'!';  // display a sub field value
    			    endwhile;
    				echo '">';
    				echo '<input type="hidden" id="a5120gsm16pp" name="a5120gsm16pp" value="';
    			    while ( have_rows('a5_digital_120gsm_uncoated') ) : the_row(); // loop through the rows of data
    			        echo the_sub_field('16pp').'!';  // display a sub field value
    			    endwhile;
    				echo '">';
    				echo '<input type="hidden" id="a5120gsm20pp" name="a5120gsm20pp" value="';
    			    while ( have_rows('a5_digital_120gsm_uncoated') ) : the_row(); // loop through the rows of data
    			        echo the_sub_field('20pp').'!';  // display a sub field value
    			    endwhile;
    				echo '">';
    				echo '<input type="hidden" id="a5120gsm24pp" name="a5120gsm24pp" value="';
    			    while ( have_rows('a5_digital_120gsm_uncoated') ) : the_row(); // loop through the rows of data
    			        echo the_sub_field('24pp').'!';  // display a sub field value
    			    endwhile;
    				echo '">';
    				echo '<input type="hidden" id="a5120gsm28pp" name="a5120gsm28pp" value="';
    			    while ( have_rows('a5_digital_120gsm_uncoated') ) : the_row(); // loop through the rows of data
    			        echo the_sub_field('28pp').'!';  // display a sub field value
    			    endwhile;
    				echo '">';
    				echo '<input type="hidden" id="a5120gsm32pp" name="a5120gsm32pp" value="';
    			    while ( have_rows('a5_digital_120gsm_uncoated') ) : the_row(); // loop through the rows of data
    			        echo the_sub_field('32pp').'!';  // display a sub field value
    			    endwhile;
    				echo '">';
    			endif; endif;

    Is there a way to further reduce this function via the use of arrays?

    Any help would be greatly appreciated

  • love arrays myself

    
    <?php 
      
      $fields = array(
        '8pp' => array(),
        '12pp' => array(),
        '16pp' => array(),
        '20pp' => array(),
        '24pp' => array(),
        '28pp' => array(),
        '32pp' => array()
      );
      if (have_rows('a5_digital_120gsm_uncoated')) {
        while(have_rows('a5_digital_120gsm_uncoated')) {
          the_row();
          foreach ($fields as $index => $values) {
            $fields[$index][] = get_sub_field($index);
          }
        } // end while have_rows
      } // end if have_rows
      foreach ($fields as $index => $values) {
        ?>
          <input type="hidden" id="a5120gsm<?php 
              echo $index; ?>" name="a5120gsm<?php 
              echo $index; ?>" value="<?php 
              echo implode('!',$values); ?>" />
        <?php 
      }
      
    ?>
    
  • You sir are a genius!

    Worked perfeclty

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

The topic ‘Repeater Sub Field Values In Array’ is closed to new replies.