Skip Navigation

[Resolved] Getting parent_id in toolset 3.0 using get_post_meta function

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

Problem:

I created a function in my existing site where I was getting parent or grand parent post id using get_post_meta function, My question is that how can I perform same in toolset 3.0.

Solution:

In Types 3.0, You can continue to maintain relation in postmeta using _wpcf_belogs_parent_id, it will be able to work in new relational table as well, and in future version of Types 3.1, we will introduce new API function to setup new post type relationship.

Relevant Documentation:

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

This support ticket is created 5 years, 11 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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

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 4 replies, has 3 voices.

Last updated by Khurram 5 years, 10 months ago.

Assisted by: Luo Yang.

Author
Posts
#905488

Tell us what you are trying to do?
I created a function in my existing site where I was getting parent or grand parent post id using get_post_meta function, using the code:

switch($post_type) {
case 'parent':
$parent_id = get_post_meta($post_id,'_wpcf_belongs_parent_id',true);
break;

case 'grand_parent':
$parent_id = get_post_meta($post_id,'_wpcf_belongs_parent-year_id',true);
$grand_parent_id = get_post_meta($parent_id,'_wpcf_belongs_grant-parent_id',true);
break;
}

My question is that how can I perform same in toolset 3.0. Would you like to share database level table details and how key management is working.

Further, that wordpress generic functions would work the same way?

Is there any documentation that you are following?

Is there a similar example that we can see?

What is the link to your site?

#905511

That code will proceed to work for all Relationships whether migrated or not if they were created previously to the update.

For new relationships that you created, we suggest to us the new API.
https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/

As you can see there are several functions, some work on legacy Relationships and other's don't.

For new relationships to get the same as your previous code did, I suggest toolset_get_related_post() or toolset_get_related_posts().

Examples can be found on the very API DOC page if you click "More Usage examples".

Please let me know if you need more help with this API using new relationships.

Note that from now on, the field we used to address in the code you shared will not exist in new relationships anymore.
Relationships are now stored in Custom Database tables and to interact with, you will need to use the API provided.

Please let us know if you need more details in regard.

#906429

Thanks Beda for explanation.

So, if I have a website built using old toolset and I migrated it to toolset 3.0. Toolset 3.0 will continue to maintain relation in postmeta using _wpcf_belogs_parent_id and in new relational table as well? Or we have to to stick to one type of code?

I have website using toolset + wpml, after migration I can use new toolset 3.0 functionality?

Regards,

Khurram

#906613

Dear Khurram,

In Types 3.0, You can continue to maintain relation in postmeta using _wpcf_belogs_parent_id, it will be able to work in new relational table as well, and in future version of Types 3.1, we will introduce new API function to setup new post type relationship.

And after migration, you should be able to use new toolset 3.0 functionality, but in case any unexpected problem, please backup your website before the migration.

#909318

Thanks for explanation. Will keep using toolset 3.0 and will update for in separate tickets for further support requirements.

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.