Skip Navigation

[Resolved] Post to post relations

The Toolset Community Forum is closed, for technical support questions, please head on to our Toolset Professional Support (for paid clients), with any pre-sale or admin question please contact us here.

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

Problem:
How do I call the Parent Post of a Child Post with PHP?

Solution:
You can use the Types API:
https://toolset.com/documentation/user-guides/many-to-many-post-relationship/ > Displaying Many-to-Many Relationship Using Types PHP API

You can also access the Parent Post ID of a given Post with WordPress API:

$parent_post_id = get_post_meta($post_id, 'wpcf_belongs_parent-post-type-slug_id', true);
This support ticket is created 8 years ago. There's a good chance that you are reading advice that it now obsolete.
This is the community support forum for Types plugin, which is part of Toolset. Toolset is a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients and people who registered for Types community support can post in it.

Sun Mon Tue Wed Thu Fri Sat
- - 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00
- - - - - - -

Supporter timezone: Asia/Ho_Chi_Minh (GMT+07:00)

This topic contains 4 replies, has 2 voices.

Last updated by kennethW 8 years ago.

Assisted by: Beda.

Author
Posts
#379880

I'm trying to have two custom posts relate to another by using Post_ID. But the most I get is meta data from using this:

<?php
$parent_id = wpcf_pr_post_get_belongs(get_the_ID(), 'sales-manager');
?>

Curious on how to pull in custom type data by doing a method like this.

#379964

What exactly do you want to achieve?

See here for what you can use the Types API you use now:
https://toolset.com/documentation/user-guides/many-to-many-post-relationship/ > Displaying Many-to-Many Relationship Using Types PHP API

You can also access the Parent Post ID of a given Post with WordPress API:

$parent_post_id = get_post_meta($post_id, 'wpcf_belongs_parent-post-type-slug_id', true);

Please let me know if you have further questions regarding the issue mentioned in this Thread

Thank you for your patience.

#380203

What I'm trying to accomplish is have two group of people associated to locations. The people will be associated to multiple locations, and need to be easily editable. (So, having both groups as parents seem like the best option.) So, each location can pull in the person information (name, contact info, title, etc) and display it.

Trying to do this via php.

#380432

This codes are used to DIPLAY things, not to SETUP relations.

To setup relations you use the Types GUI
In the Post Edit screens you set the relations:
https://toolset.com/documentation/user-guides/creating-post-type-relationships/
Above are single relations.

For many to many relations, this applies:
https://toolset.com/documentation/user-guides/many-to-many-post-relationship/

1. What I'm trying to accomplish is have two group of people associated to locations.

I unterstand both are Post Types, right?
As users (WP Users) can not be associated with Post Types, other than with the Authorship

2. The people will be associated to multiple locations, and need to be easily editable.

Since you have probably 2 Custom Post Types for Peoples, and one for Locations, you will proceed as this:

Either Peoples are parent of Locations, which allows you to have many locations for ONE people.

OR, you have Locations parent to Peoples, which allows you to have ONE Location for many Peoples.

OR, you set a intermediate Post Type, so you can have many Peoples with many locations.

3. You can then either display this with Views, or PHP.

Please let me know if you have further questions regarding the issue mentioned in this Thread

Thank you for your patience.

#390591

The forum ‘Types Community Support’ is closed to new topics and replies.

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