Support

Account

Home Forums General Issues Mixing foreach and while loops

Unread

Mixing foreach and while loops

  • Hi guys,

    I am having trouble with getting some code to play nice.

    Here is the setup: (I am working in the latest WordPress with the latest version of ACF PRO)
    I have created a page and have a repeater on it with 3 subfields. One of these subfields pulls in the general taxonomies under post.

    I need to output each taxonomy individually and then check to see if any of the rows have an entry for that taxonomy.

    Here is an example (each city is a taxonomy):
    Worker A will travel to City A, City B, and City C
    Worker B will travel to City B and City C
    Worker C will travel to City A and City C

    Desired Output
    City A
    Worker A
    Worker C

    City B
    Worker A
    Worker B

    City C
    Worker A
    Worker B
    Worker C

    Currently, it just repeats all names under each taxonomy. Please help (please and thank you)!

    <?php // get regular list of tags and during the foreach, check to see if there is a reviewer for that tag / run rows then if genre == that term, proceed
    
    						$tags = get_tags(array(
    							'hide_empty' => false
    							));
    							echo '<ul>';
    								foreach ($tags as $tag) {
    									
    									echo '<li>';
    									
    										echo $tag->name;
    									 	
    									
    												if( have_rows('reviewer_info') ):
    												echo '<ul>';
    													while ( have_rows('reviewer_info') ) : the_row();
    														echo '<li>';
    																echo the_sub_field('reviewer_name');
    														echo '</li>';
    													endwhile;
    												echo '</ul>';
    												endif;
    									
    									echo '</li>';
    								}
    							echo '</ul>'; ?>
Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.