Problem:
I am trying to retrieve the post ID of a related post connected through a specific Toolset Post Reference Field in PHP, but using get_post_meta() returns an empty string, and I need to avoid fetching all related posts of the same type.
Solution:
Use toolset_get_related_post( $post_id, 'relationship-slug' ) to retrieve the post ID tied specifically to the Post Reference Field; it returns the related post ID or 0 if none is found.
Example:
$related_post_id = toolset_get_related_post( 123, 'advisor' ); if ( $related_post_id ) { echo 'Related post ID: ' . $related_post_id; } else { echo 'No related post found.'; }
Relevant Documentation:
https://toolset.com/documentation/programmer-reference/views-filters/
This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.
Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.
This topic contains 1 reply, has 1 voice.
Last updated by 3 weeks ago.
Assisted by: Christopher Amirian.