Skip Navigation

[Resolved] Cannot find fully-correct instructions for getting related posts

This thread is resolved. Here is a description of the problem and solution.

This support ticket is created 6 years, 1 month 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
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10: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/Kolkata (GMT+05:30)

This topic contains 7 replies, has 3 voices.

Last updated by Clifford 6 years, 1 month ago.

Assisted by: Minesh.

Author
Posts
#1136302

Link to documentation page: https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/

This code works for me when a 'sitter' custom post type has a one-to-many with 'products' post type (Sitter is the parent):

new WP_Query(
	[
		'post_type' => 'product',
		'toolset_relationships' => [
			'role' => 'child',
			'related_to' => $sitter_post,
			'relationship' => 'sitter-products'
		],
	]
);

I didn't actually find *working* code examples *anywhere*.

https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/how-to-migrate-your-site-to-new-post-relationships/ has a "NEW APPROACH" snippet, but I think you should add:
- an explanation of what this relationship is
- an explanation of what this query is expected to return
- fix the 'relationship' to be a string, since an array (['sitter','product']) is for legacy relationships
- a link to the official/current documentation, since https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_get_related_posts seems to be legacy information, as it's not WP_Query

#1136737

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Well - I do not know if you missed it by mistake but all available query argument is documented here with the explanation:
=> https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/how-to-migrate-your-site-to-new-post-relationships/#full-documentation-of-the-query-argument

Now, regarding toolset_get_related_posts() , no its not a legacy function but you should feel free to use it with your new relationships.

For example:

$related_post_ids = toolset_get_related_posts(
                                    $parent_id,
                                    'clinic-location',
                                     'parent',
                                     100,
                                      0,
                                      array(),
                                     'post_id',
                                     'child'
                                     );

Please check this related ticket:
=> https://toolset.com/forums/topic/retrieving-multiple-child-post-ids/#post-1079482

#1136964

I did miss that bit; thanks for letting me know. Despite this section of text existing, I think the other feedback I had is still applicable.

#1137517

Hi,

Minesh isn't available, he has one day vacation, you will get the response ASAP when he back on Thursday.

#1138156

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Well - at top of the page we already wrote that:
=> https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/how-to-migrate-your-site-to-new-post-relationships/

On this page, we will use "legacy" for referring to the old post relationship features before the Types 3.0 release. Please note that the Types 2.2.22 release added the new Post Relationships API to the legacy relationships.

We also added the following that after activating the new post relationships you need to use slug:

However, for relationships created after activating the new post relationships, this will not work and the relationship slug must be used instead.

So It seems all fine here and we can close it here.

#1140178

I'd ask that your content team look into the readability/clarity of this article based on my feedback.

#1140199

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Yes - I will share your feedback with our Doc team. Thank you. Feel free to close this ticket.

#1141290

Thank you for having your Doc Team review this article for easy/clear understanding via quick reference.