Skip Navigation

[Resolved] toolset_get_related_posts

This support ticket is created 6 years, 4 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
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

Author
Posts
#1107509

Hi there,
I am using Toolset Types on my site to create multiple custom posts with custom field groups.
Home Design & FACADES are the custom posts and connected by each other using Toolset relationship option.
Now, in the functions.php file of my theme, I am trying to fetch the related posts using "toolset_get_related_posts" but it's coming back with the empty array.
Please take a look at functions.php line 47. I have already created the account for you to test and debug it. Please find the details below.

site link: hidden link
url link: hidden link
output page: hidden link
username: toolset
password: toolset123

Any kind of help will be appreciated.
Thanks
Sohaib
sohaib@woof.com.au

#1107646

Hi, a few things to fix:
1. The array syntax in this line will not work, because none of your relationships were migrated from a legacy site. The relationships were all created in the new relationship system, so you must use the relationship slug syntax instead, as in the previous line of your code. Delete this line:

$facade = toolset_get_related_posts( $post->ID, array('home-design', 'facade'), 'parent');

2. The first 8 arguments for the toolset_get_related_posts API are all usually required. Without any of those 8 arguments, you will probably not receive any results. I made the following change in functions.php, and now you can see the var dump in the editor screen:

//Get the REGIONS and show fields the times the regions are associated with the Fields
	$terms = get_the_terms( $post->ID, 'region');
	foreach($terms as $term){
		$facade = toolset_get_related_posts( 
			$post->ID, 
			'home-design-facade', 
			'parent', 
			1000000,
			0,
			array(),
			'post_object',
			'child'
		);
		//$facade = toolset_get_related_posts( $post->ID, array('home-design', 'facade'), 'parent');
		var_dump($facade);
	}

Documentation for this API here:
https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_get_related_posts