Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
ACF Relationship Code
<?php //<~ don't add me
add_shortcode( 'tl_related_lights', 'tl_related_lights_relationship' );
// Add Relationship ACF field between Projects and Lights
function tl_related_lights_relationship() {
$posts = get_field('tl_project_lights_link_used');
if( $posts ): ?>
<?php foreach( $posts as $p ): // variable must NOT be called $post (IMPORTANT) ?>
<a href="<?php echo get_permalink( $p->ID ); ?>"><?php echo get_the_title( $p->ID ); ?></a>
<?php endforeach; ?>
<?php endif; ?>
return ob_get_clean();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment