Skip to content

Instantly share code, notes, and snippets.

@axeldevo
Created March 18, 2014 17:56
Show Gist options
  • Save axeldevo/9625623 to your computer and use it in GitHub Desktop.
Save axeldevo/9625623 to your computer and use it in GitHub Desktop.
Bi-directional relationship URL
<?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 ) ) {
foreach ( $related as $rel ) {
//get id for related post and put in ID
//for advanced content types use $id = $rel[ 'id' ];
$id = $rel[ 'ID' ];
//show the related post name as link
echo '<a href="'.get_permalink($id).'">'.get_the_title( $id ).'</a>';
} //end of foreach
} //endif ! empty ( $related )
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment