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
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.
Thanks Christian. Let me know what you find out...
- Chris
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.
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
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.