I spent the entire night yesterday scouring the net and ended up banging my head against the wall. Iâm probably missing something obvious, so I thought Iâd write here in hopes of some guidance.
Iâm a relative novice when it comes to PHP. I want to know how to add some conditionals to some fields that are repeating using the Advanced Custom Fields plugin for WordPress (with the Flexible Content and Repeater Fields add-ons). 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'];
}
}
}
}
} ?>
Use :