Skip to content

Instantly share code, notes, and snippets.

@axeldevo
Created March 19, 2014 19:02
Show Gist options
  • Save axeldevo/9648855 to your computer and use it in GitHub Desktop.
Save axeldevo/9648855 to your computer and use it in GitHub Desktop.
Relationships using Advanced Content Types
<?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