Skip Navigation

[Resolved] Setting post relationship in Types 3.0 using Post Relationship API

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

Problem: I have a form that creates child posts, and I would like to link them to a parent post in the new relationships system. How can I set a post relationship between two posts using the Post Relationship API?

Solution: This feature is not going to be available immediately when Types 3.0 is released, and unfortunately we do not have a public API available yet. If you need to set post relationships programmatically, I do not recommend upgrading.

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

This support ticket is created 6 years, 6 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
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 5 replies, has 2 voices.

Last updated by Christian Cox 6 years, 6 months ago.

Assisted by: Christian Cox.

Author
Posts
#843056

I've a question about setting post relationships in the new Types 3.0 beta model.

I have a site with two custom post types, 'properties' and 'developments', where a property can be a child of a development. Under the old system, I could set up this relationship using a statement such as:

update_post_meta($post_id, '_wpcf_belongs_developments_id', $development_id );

I've read the page on the new Post Relationships API (https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/) which gives very helpful functions for retrieving post relationships, but it doesn't mention how I can set new ones or update existing ones.

Can you point me in the right direction please?

Thanks,

Chris

#846516

We're still working on the public API, and the "set" methods are not yet available. Let me get the latest information about this from the team, and I will update you shortly.

#846868

Thanks Christian. Let me know what you find out...

- Chris

#858417

The latest information I have received is that this API will not be available for the upcoming 3.0 release, and is planned for a future version. If you need to create post relationships programmatically in CRED, I can't recommend updating until that's ready.

#858589

Hi Christian,

OK, thanks for the update.

Yes, we do need to set the relationship programmatically from a front-end form (not actually using CRED, but a custom form), so I think I'll hold off upgrading for now.

Thanks anyway for looking into it!

All the best,

Chris

#872627

Hi Chris, I had a bit more discussion with the team about this and it appears there were some miscommunications. I would like to clear those up. Here's what I know now:
- If you have a post relationship in the legacy system and you are using custom code to set the parent post using _wpcf_belongs_slug_id, this legacy code will continue to work in the new system after migration. There is a backwards compatibility layer built in to help bridge these systems.
- After migraton, if you create a new post relationship, the legacy method will not work. Using the _wpcf_belongs_slug_id meta key is not sufficient to establish these new relationships. A new API will be available that will allow you to set these relationships, and that API will be published along with the 3.0 release.

Sorry for the confusion here, if you have any follow-up questions feel free to reopen the ticket.