Support

Account

Home Forums Front-end Issues Relationship Fields as string output Reply To: Relationship Fields as string output

  • Hi @erni41

    The relationship field will return an array of post objects. You can create a string representation of the post titles by looping through and echoing them out.

    Like so:

    
    <?php 
    
    $cities = get_field('field_name');
    $output = array();
    
    if( $cities )
    {
    	foreach( $cities as $city )
    	{
    		$output[] = get_the_title( $city->ID );
    	}
    }
    
    ?>
    <h3>Location: <?php echo implode(', ', $output); ?></h3>