Support

Account

Home Forums Add-ons Repeater Field Print array value of sub-field in a repeater

Helping

Print array value of sub-field in a repeater

  • I have a repeater with two sub-fields
    1. A relationship field which points to a CPT
    2. A date and time field

    I am using the following code in post’s single.php to output these values

    <?php 
     
    $rows = get_field('theatre');
    if($rows)
    {
    	echo '<ul>';
    
    	foreach($rows as $row)
    	{
    	
    		echo '<li>sub_field_1 = ' . $row['theatre_name'] . ', sub_field_2 = ' . $row['start_date'] .', etc</li>';
    	}
     
    	echo '</ul>';
    }
    
    ?>

    This is the output I get.

    sub_field_1 = Array, sub_field_2 = 2/14/14 5:00 pm, etc
    sub_field_1 = Array, sub_field_2 = 2/15/14 1:00 pm, etc

    Could you guide me on how to get the value for that array instead of just “Array” and also how to make a hyperlink to that CPT ?

    Thanks

  • Hi @sri

    Something like this would work:

    
    <?php 
    
    $theatre = $row['theatre_name'];
    $theatre = current($theatre);
    
    echo '<li>sub_field_1 = ' . get_the_title($theatre->ID) . ', sub_field_2 = ' . $row['start_date'] .', etc</li>';
    
    ?>
    

    Please remember that the relationship will return an array of post objects.

    Thanks
    E

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

The topic ‘Print array value of sub-field in a repeater’ is closed to new replies.