Skip to content

Instantly share code, notes, and snippets.

Embed
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() {
ob_start();
$posts = get_field('tl_project_lights_link_used');
if( $posts ): ?>
<ul>
<?php foreach( $posts as $p ): // variable must NOT be called $post (IMPORTANT) ?>
<li>
<a href="<?php echo get_permalink( $p->ID ); ?>"><?php echo get_the_title( $p->ID ); ?></a>
</li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
<?php
return ob_get_clean();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.