Home › Forums › Front-end Issues › relationship query which MAY only have one result › Reply To: relationship query which MAY only have one result
<?php
$cities = get_field('related_city');
if ($cities) {
echo "<hr><h3>This event happens in</h3>";
if (count($cities) == 1) {
?><a href="<?php echo get_the_permalink($cities[0]);?>"><?php echo get_the_title($city); ?></a>(Click to see other <?php echo get_the_title($city); ?> Events)<?php
} else {
foreach ($cities as $city) { ?>
<li><a href="<?php echo get_the_permalink($city);?>"><?php echo get_the_title($city); ?></a>(Click to see other <?php echo get_the_title($city); ?> Events)</li>
<?php
}
}
}
?>
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.