Showing link to post with bi-directional relationship
-
I have two custom post types that share a bi-directional relationship field. On one where there can be several relationships (“organizations” may have multiple “opportunities”) I can display the associated field just fine using a snippet found here: https://pods.io/tutorials/get-values-from-a-custom-relationship-field/
The other content type “opportunity” can have only one related field for “organization”. I am trying to show a link to the organization using this modified snippet:
<?php
//get Pods object for current post
$pod = pods( ‘opportunity’, get_the_id() );
//get the value for the relationship field
$related = $pod->field( ‘organization’ );
//loop through related field, creating links to their own pages
//only if there is anything to loop through
if ( ! empty( $related ) ) {
echo ‘‘.’Organization:’;//show the related post name as link
echo
‘‘.get_the_title( $id ).’‘ ;
//get the value for some_field in related post and echo it} //endif ! empty ( $related )
?>
Unfortunately the link that shows is a link back to the current “opportunity” …. any ideas what I am doing wrong? — thanks in advance, and I think PODS is terrific!
- The topic ‘Showing link to post with bi-directional relationship’ is closed to new replies.