How can I output Relationship fields in one row (as string with comma seperated)?
I have two CPT, CARS and CITIES and want to show the cities in the single-portfolio page of the cars post-type like this:
Location: Boston, Paris
Thank’s for your help
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>
This reply has been marked as private.
This reply has been marked as private.
Hi @erni41
To answer your second question, please use a text field for any URL data.
For your first, I don’t belivee I have yet read the email but can you check that the global $post->ID value is that of the correct post? Perhaps ACF is loading data from the wrong post?
Thanks
E