Created
March 18, 2014 17:56
-
-
Save axeldevo/9625623 to your computer and use it in GitHub Desktop.
Bi-directional relationship URL
This file contains hidden or 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 ) ) { | |
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