Created
August 6, 2018 06:29
-
-
Save neilgee/6bd6265d5c4a062a20041986d5305d15 to your computer and use it in GitHub Desktop.
ACF Relationship Code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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