Skip to content

Instantly share code, notes, and snippets.

@neilgee
Created August 6, 2018 06:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save neilgee/6bd6265d5c4a062a20041986d5305d15 to your computer and use it in GitHub Desktop.
Save neilgee/6bd6265d5c4a062a20041986d5305d15 to your computer and use it in GitHub Desktop.
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