Skip Navigation

[Resolved] POST a many-to-many relationship CPT through WP API

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

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10: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/Kolkata (GMT+05:30)

This topic contains 2 replies, has 2 voices.

Last updated by parisK 3 years, 7 months ago.

Assisted by: Minesh.

Author
Posts
#2162669

Tell us what you are trying to do?
My issues continue from the ticket here: https://toolset.com/forums/topic/cant-expose-relationship-intermediary-posts-to-wp-api/
As in the link above what I'm trying to do is to POST a relationship through the WP API. My initial thought was to use the WP API and by using python to POST my data to the API endpoint. However, probably the relationship CPT uses an additional table to store the links between the objects, so the API won't simply expose two fields (e.g. parent-object, child-object) to set up the relationship. I thought that this would be easy, fill in the parent and the child and it's over. As I understand there is no way to confront this limitation, is that true?

So my second thought was to go with a relationship form and POST the relationship with python once again. If this is the case, is there any documentation I can follow?

General idea: I have job openings and candidates and I want to create many-2-many relationships, meaning "a candidate may fit many job openings, and a job opening may fit multiple candidates". This "fitting" is an automated process that will take place off WordPress. I need a way to POST the new relationships to the database, either through a post endpoint (first case above) or a post form (second thought). Any ideas on that?

Thank you in advance

#2162705

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Have you try to use the post relationship API function: toolset_connect_posts() to connect the post of many to many post relationship?
=> https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_connect_posts

#2163611

My issue is resolved now. Thank you!
Hi Minesh, thank you for your quick response.
That's interesting yes, I followed the process described here: https://toolset.com/forums/topic/continued-connect-multiple-child-posts-to-parent-in-one-move/

Your comment didn't solve my problem directly rather it gave me a good direction on how I should proceed.
So I have to redesign my approach as I can't create the relationships from python that was my initial thought.
What I plan to do, is to use python to create the couples, store them to a CSV, upload them to WordPress and create a corn job that will read the file and use the toolset_connect_posts() to post the relationships. This workaround should do the job.
Thank you