Home › Forums › Add-ons › Repeater Field › 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
}
?>
The topic ‘Repeater Sub Field Values In Array’ is closed to new replies.
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!
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 Privacy Policy. If you continue to use this site, you consent to our use of cookies.