Skip Navigation

[Resolved] relationsships changed – need te intermediari id

This support ticket is created 2 years, 5 months ago. There's a good chance that you are reading advice that it now obsolete.

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.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)

Author
Posts
#2374345

Can you help me? the relationships in toolset has changed also in the database. Previously I had below shortcode to get the intermediary_id back. How do I do that now? Is there a new shortcode for that?


// Add Shortcode
function img_relatieid( $atts ) {

	// Attributes
	$atts = shortcode_atts(
		array(
			'loc' => '5807',
			'prod' => '354',
		),
		$atts
	);

    
	global $wpdb;
	$table_name = $wpdb->prefix . "toolset_associations";
	
	$locatie = do_shortcode('[wpv-post-id]');
	$product = do_shortcode('[wpv-post-id item="$current_page"]');
	
	
	$relatieid = $wpdb->get_results("SELECT * FROM $table_name WHERE parent_id = $product AND child_id = $locatie");
	
	if (count($relatieid)> 0){
   
     foreach ($relatieid as $row) { 

	       return $row->intermediary_id; 
	 }

		} else {
		  return 9999;
		}
	  
	

}
add_shortcode( 'imgrelatieid', 'img_relatieid' );
#2374535

Hi,

Thank you for contacting us and I'd be happy to assist.

It has been quite a while since the post-relationship structure has been changed, which is why this old shortcode no longer works.

To get the related 'intermediary' post ID, when 'parent' and 'child' post ID is known, you can use the "toolset_get_related_posts" function in your shortcode:
https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_get_related_posts

For example:


// Add Shortcode
function img_relatieid( $atts ) {

	// Attributes
	$atts = shortcode_atts(
		array(
			'loc' => '5807',
			'prod' => '354',
			'rel_slug' => '',
		),
		$atts
	);

	$locatie = do_shortcode('[wpv-post-id]');
	$product = do_shortcode('[wpv-post-id item="$current_page"]');
	$relationship_slug = $atts['rel_slug'];

	// Get the related 'intermediary' post
	$relatieid = toolset_get_related_posts(
		[ 
			'parent' => $product,
			'child' => $locatie
		],
		$relationship_slug,
		[
			'role_to_return' => 'intermediary'
		]
	);

	if (count($relatieid)> 0) {
		foreach ($relatieid as $item) {
			return $item; 
		}
	} else {
		return 9999;
	}

}
add_shortcode( 'imgrelatieid', 'img_relatieid' );

Note: To use this updated shortcode, you'll need to provide the relationship's slug, in the 'rel_slug' attribute, like this:


[imgrelatieid rel_slug="product-location"]

You'll replace 'product-location' with the actual slug of your relationship.

I hope this helps and for more personalized assistance around custom code, you can also consider hiring a professional from our list of recommended contractors:
https://toolset.com/contractors/

regards,
Waqar

#2376917

My issue is resolved now. Thank you!