Skip Navigation

[Resolved] toolset_get_parent_post_by_type API not finding posts

This support ticket is created 3 years, 3 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 6 replies, has 2 voices.

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

Assisted by: Luo Yang.

Author
Posts
#1904519

Tell us what you are trying to do?

I am trying to update this outdated line of code:
$post_meta = get_post_meta($post_id);
$fairId = $post_meta["_wpcf_belongs_fair_id"][0];

I tried the following:

$booth = get_post($post_id);
$fairId = toolset_get_parent_post_by_type($booth, 'fair' );

I also tried:

$fairId = toolset_get_parent_post_by_type($post_id, 'fair' );

However, the parent id keeps returning 0 even though there should be a parent for this post. The outdated approach
$post_meta = get_post_meta($post_id);
$fairId = $post_meta["_wpcf_belongs_fair_id"][0];

returns the correct value. What am I doing wrong?

Is there any documentation that you are following?
https://toolset.com/forums/topic/new-posts-created-with-toolset-forms-not-connecting-to-parent/
https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/

What is the link to your site?
hidden link

#1904763

Hello,

I assume we are talking about one-to-many relationship, and it is created with the latest version of Toolset Types plugin, you are going to get parent post information in child post.

If it is, please try the relationship API function toolset_get_related_post(), see our document:
https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_get_related_post

#1909317

Hi Luo,

Yes, we are talking about a one-to-many relationship. I will try the relationship API function toolset_get_related_post() and report back if there are any issues.

#1909991

Please update here if you need more assistance for it.

#1918045

Hi Luo,

I am still have issues getting this to work. I have tried the following, but the fair post (parent) returns "0" even though there is a parent for the post:

Version 1
$booth = get_post($post_id);
$fairId = toolset_get_related_post( $booth, array( 'fair', 'booth' ) );

Version 2
$booth = get_post($post_id);
$fairId = toolset_get_related_post( $booth, array( 'booth', 'fair' ) );

Please let me know if you would like access to the site.

#1918357

OK, please provide your website access in below private message box, also point out the problem page URLs, and where I can edit your custom PHP codes, thanks

#1919905

Thanks for the details, you are using cred_save_data action hook, in this action hook, you can get parent post ID with PHP post variable $_POST['@fair_booth_parent'].

For example:

$fairId = isset($_POST['@fair_booth_parent'])?$_POST['@fair_booth_parent']:''; //modified here
This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.