Support

Account

Home Forums Add-ons Flexible Content Field Help adding conditionals to nested repeater field within a flexible field

Unread

Help adding conditionals to nested repeater field within a flexible field

  • I’ve spent the entire night scouring the net and have ended up banging my head against the wall. I’m probably missing something obvious, so I thought I’d post here in hopes of a solution.

    I’m a relative novice when it comes to PHP. I want to know how to add some conditionals to my repeater fields. Below I’ve pasted the code that I’m using. The repeater field has many sub-fields. I’m having trouble figuring out how to include or exclude some text alongside the sub-field whether or not the sub-field has any info plugged into it. For example, if the user doesn’t enter some info for the field ‘director’, how can make it not say “Directed by”?

    <?php               
    	if (get_field("production_history_flexible")){
    		while (has_sub_field("production_history_flexible")){
    			if (get_row_layout() == "season_date"){
    				echo '<h2 class="surtitle">';
    				the_sub_field("season_date_entry");
    				echo '</h2>'; 
    			}  
    
    	if (get_row_layout() == "archive_entry"){  
    		
    	$rows = get_sub_field('archive_entry_repeater'); //Repeater Field Name
    
    	if ($rows){ 
    		foreach($rows as $row){
    			echo '<p class="surtitle">'.$row['surtitle'].'</p>'; 
    			echo '<h3>'.$row['title'].'</h3>'; 
    			echo '<h4>by '.$row['writer'].'</h4>'; 
    			echo '<ul>';
    			echo '<li>Directed by '.$row['director'].'</li>'; 
    			echo '<li>Performed by '.$row['performers'].'</li>';
    			echo '<li>'.$row['dates'].'</li>'; 
    			echo '<li>'.$row['venue'].'</li>'; 
    			echo '</ul>'; 
    			echo $row['description'];
    			}	
    		}
    	}
    	}
    } ?>
Viewing 1 post (of 1 total)

The topic ‘Help adding conditionals to nested repeater field within a flexible field’ is closed to new replies.