I’m using ACF with flexible content and within that a relationship field to display a single link on the logo. I’ve set the maximum links to one, so don’t need a loop to display multiple links, I just need the URL for one relationship link.
$clnk is the link and it needs to be displayed within the href tag, i.e.
<a href="' . $clnk . '"><img class="client_logos" src="' . $cl . '" alt="" /></a>
But the link itself is coming up as /Array ?
Any help would be appreciated.
<h2>Our clients</h2>
<div class="services_container" style="display: block;">
<?php
// check if the flexible content field has rows of data
if (have_rows('clients')):
// loop through the rows of data
while (have_rows('clients')) : the_row();
if (get_row_layout() == 'clients'):
$tl = get_sub_field('client_group_name');
echo '<h2>' . $tl . '</h2>';
endif;
// Check rows repeater
echo '<div class="clients_container">';
if( have_rows('client_details') ):
// Loop through rows.
while( have_rows('client_details') ) : the_row();
// Load sub field value.
$cl = get_sub_field('client_logo');
$cn = get_sub_field('client_name');
$clnk = get_sub_field('client_link');
echo '<a href="' . $clnk . '"><img class="client_logos" src="' . $cl . '" alt="" /></a>';
// End loop.
endwhile;
endif;
echo '</div>';
endwhile;
endif;
?>
</div><!--clients container-->
</div>
>Solution :
The official documentation for Relationship fields indicates that it will always return an array of the selected posts.
Adjusting your code to expect an array is simple enough (untested):
$clnks = ( array ) get_sub_field( 'client_link' );
$clnk = array_pop( $clnks );
printf( '<a href="%s">', get_permalink( $clnk ) );
May want to consider changing the field type from Relationship to Link.