Support

Account

Home Forums Backend Issues (wp-admin) How to print values from groups within groups

Helping

How to print values from groups within groups

  • I am trying to print a list of Committee Members. I have a group called com_members and then a group for each member that contains title, text and image. What is the most efficient way of printing this information on my WordPress page? At the moment I have the following. Is there a more efficient way of writing this? Anyone know? I am using Advanced Custom Fields free edition.

    <?php
    				if( have_rows('com_members') ):
    				    while ( have_rows('com_members') ) : the_row();
    					    	if( have_rows('member1') ): //?????
    					    		while ( have_rows('member1') ) : the_row();
    					    			echo "Member 1 <br/>";
    							        $title = get_sub_field('title');
    							        echo $title . "<br/>";
    							        $image_url = get_sub_field('image');
    							        echo $image_url . "<br/>";
    							        $text = get_sub_field('text');
    							        echo $text . "<br/>";
    							    endwhile;
    							else:
    								//nothing
    							endif;
    							if( have_rows('member2') ): //?????
    					    		while ( have_rows('member2') ) : the_row();
    					    			echo "Member 2 <br/>";
    							        $title = get_sub_field('title');
    							        echo $title . "<br/>";
    							        $image_url = get_sub_field('image');
    							        echo $image_url . "<br/>";
    							        $text = get_sub_field('text');
    							        echo $text . "<br/>";
    							    endwhile;
    							else:
    								//nothing
    							endif;
    							if( have_rows('member3') ): //?????
    					    		while ( have_rows('member3') ) : the_row();
    					    			echo "Member 3 <br/>";
    							        $title = get_sub_field('title');
    							        echo $title . "<br/>";
    							        $image_url = get_sub_field('image');
    							        echo $image_url . "<br/>";
    							        $text = get_sub_field('text');
    							        echo $text . "<br/>";
    							    endwhile;
    							else:
    								//nothing
    							endif;
    				    endwhile;
    				else :
    				    // no rows found
    				endif;
    			?>
Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.