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
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
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.
Please update here if you need more assistance for it.
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.
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
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