I am making a artist portfolio site in wordpress. I am working on a single page for a custom post type Artwork, which contains numerous metadata fields created using ACF. I have run into trouble displaying the contents of an ACF repeater field with the names of collaborators, if there are any, who contributed to the artwork linked to their personal sites if they have one. This repeater is cloned as one element into the Artwork Field group.
I have been able to display the collaborators' names with and without links using the code below. So it will display "Co-creators: Name1 (with href)Name2 (no href)". But the commas don't show up between the collaborators. I think it is because I am not creating the arrays properly.
Any help would be greatly appreciated.
<?php
while (have_posts()) : the_post();
// lots more code here
$artwork_collaborators = get_field('artwork_collaborators'); // get the value of the acf clone field
if ($artwork_collaborators) : // check if has data ?>
<dd id="single-artwork-collaborators"><?php
_e('Co-creators: ', 'aopa'); // multilanguage label for translation
foreach ($artwork_collaborators as $artwork_collaborator) : // foreach loop to get all collaborators
if ($artwork_collaborator['artwork_collaborator_url']) : // check if there is a url for the collaborator
$array_collaborators = array('<a href="'. $artwork_collaborator['artwork_collaborator_url'] . '" target="_blank">' . $artwork_collaborator['artwork_collaborator_name'] . '</a>'); // create array with URL
else :
$array_collaborators = array($artwork_collaborator['artwork_collaborator_name']); // create array without url
endif;
$collaborator_string = implode(", ", $array_collaborators); // implode the array and add commas
echo $collaborator_string; // echo the collaborators with link or no link separated by commas if there is more than one
endforeach; ?>
</dd>
<?php endif;
// lots more code here
endwhile?>