Skip Navigation

[Resolved] parent always returns 0

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

Problem:

Get parent post information with the latest version of Types functions.

Solution:

For the new one-to-many relationships, please try another function: toolset_get_related_post()

Relevant Documentation:

https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_get_related_post

This support ticket is created 6 years, 2 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/Hong_Kong (GMT+08:00)

This topic contains 3 replies, has 2 voices.

Last updated by Luo Yang 6 years, 2 months ago.

Assisted by: Luo Yang.

Author
Posts
#1167182
FireShot Capture 9 - Brouwerijen Bieren Bewerken - R_ - https___belgian-beer.club_wp-admin_admin.php.png

I am trying to: get the parent ID

Link to a page where the issue can be seen: -

I use this code :

$parent_id = toolset_get_parent_post_by_type(get_the_id(), 'brouwerij' );
echo "brouwerij : " . $parent_id;

When there is a relation from one to many
1 brewery can have multiple beers

The function always returns 0

#1167408

Hi,

The Types function toolset_get_parent_post_by_type() is for legacy parent/child relationship created by old version of Types plugin, see our document:
https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_get_parent_post_by_type
Retrieves an ID of the parent post, using a legacy post relationship

For the new one-to-many relationships, please try another function: toolset_get_related_post()
https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_get_related_post
Retrieve an ID of a single related post.
You can get the example codes by clicking link "Usage examples"

#1167929

My issue is resolved now. Thank you!

#1168030

You are welcome