Get ID of single related posts with ShortCode (also for RFG)

With this ShortCode you will receive a Single Post ID of a Single Related Post, if you insert it either to any post in a relationship, or into a View, that queries posts in a relationship.
This can be RFG as well.

The ShortCode needs to be adjusted to your case, specifically the $relationship parameter must be adjusted.
That value should either be the Relationship Slug, or Slug of the Repeating Post Field Group.

function toolset_get_related_post_shortcode_callback( $atts ){
	global $post;
	$current_post_id 		 = $post->ID;
	$relationship 	 		 = 'slug of relationship, OR of RFG Field Group slug, if this is a current RFG post';
	$current_rfg_parent_post = toolset_get_related_post( $current_post_id, $relationship );
	$out = $current_rfg_parent_post;
	return $out;
}
add_shortcode( 'toolset-related-single-post', 'toolset_get_related_post_shortcode_callback' );

You must register this ShortCode in Toolset > Settings > Front end Content > Third party ShortCodes, as other wise it will break your output.


Let us know if this snippet is not working for you:

This snippet doesn’t work
0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments