Support

Account

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
    					}
    				}
    			}
    		?>