Home Forums Front-end Issues Select fields in repeater, in repeater…


Select fields in repeater, in repeater…

  • I am pushing myself a little here and need some help please;

    I am trying to have a multiple select area in a repeater, in a repeater…

    This is code I have so far;

    <?php while ( have_posts() ) : the_post(); ?>
    	// check for rows (parent repeater)
    	if( have_rows('certificate_area') ): ?>
    		<div id="certificate_area">
    			<div class="flex-wrapper">
    				// loop through rows (parent repeater)
    				while( have_rows('certificate_area') ): the_row(); ?>
    					// check for rows (sub repeater)
    					if( have_rows('item') ): ?>										
    						// loop through rows (sub repeater)
    						while( have_rows('item') ): the_row();
    						// display each item as a list - with a class of completed ( if completed )
    						<div class="flex-shell <?php the_field('class'); ?>">
    							<div class="flex-item">
    								<div class="image">
    									<a href="<?php the_sub_field('image'); ?>" class="fancybox">
    										<img src="<?php the_sub_field('image'); ?>" alt=""> 
    								<div class="copy">
    									<h2><?php the_sub_field('title'); ?></h2>
    									<p><?php the_sub_field('overview'); ?></p>
    									<div class="icon">
    											$images = array(
    											  'Electrical' => get_template_directory_uri(). '/dist/images/elec-icon.png',
    											  'Lighting' => get_template_directory_uri(). '/dist/images/lights-icon.png',
    											$values = get_field('area');
    											foreach ($values as $value) {
    											  <img src="<?php echo $images[$value] ?>" alt="">
    											var_dump( $images );
    					<?php endwhile; ?>									
    				<?php endif; //if( get_sub_field('items') ): ?>																
    		<?php endwhile; // while( has_sub_field('to-do_lists') ): ?>
    	<?php endif; // if( get_field('to-do_lists') ): ?>
    <?php endwhile; // end of the loop. ?>

    As in the select section (near the bottom) I am getting the following error;

    Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\napit-desktop-website-wp\wp-content\themes\napit-desktop-website\templates\template-certificates.php on line 63

    I have turned on debug and it added;

    array(2) { [“Electrical”]=> string(107) “//localhost:3000/desktop-website-wp/wp-content/themes/desktop-website/dist/images/elec-icon.png” [“Lighting”]=> string(109) “//localhost:3000/desktop-website-wp/wp-content/themes/desktop-website/dist/images/lights-icon.png” }

    Can anyone help please?

  • Hi @forbiddenchunk

    I believe it has something to do with this code:

    $values = get_field('area');

    If the “area” field is located in a repeater, you should get the value like this:

    $values = get_sub_field('area');

    If that doesn’t help, could you please share the JSON export file of your field group so I can test it out on my installation?

    Thanks 🙂

  • Hi @acf-support

    That worked, thanks! Can’t believe I didn’t realise it needed to be a sub field

    Thanks 🙂

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

The topic ‘Select fields in repeater, in repeater…’ is closed to new replies.