Created
March 19, 2014 19:02
-
-
Save axeldevo/9648855 to your computer and use it in GitHub Desktop.
Relationships using Advanced Content Types
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 | |
//get the value for the relationship field | |
$related = $obj->field( 'company_investors' ); | |
//loop through related field, creating links to their own pages | |
//only if there is anything to loop through | |
if ( ! empty( $related ) && is_array($related) ) { | |
$output = array(); | |
foreach ( $related as $rel ) { | |
//get id for related investor and put in id | |
//get name for related investor and put in name | |
$id = $rel[ 'id' ]; | |
$name = $rel[ 'investor_name' ]; | |
//show the related post name as link | |
$output[] = '<a href="'.site_url( 'investor/' . $rel[ 'permalink' ] ).'">' . $name . '</a>'; | |
} //end of foreach | |
echo implode(', ',$output); | |
} //endif ! empty ( $related ) | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment