Skip Navigation

[Resolved] Create new custom post type and connect it to an existing cpt by field

This support ticket is created 4 years, 8 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
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 3 replies, has 2 voices.

Last updated by Christian Cox 4 years, 8 months ago.

Assisted by: Christian Cox.

Author
Posts
#1528925

I have an existing custom post type 'movies' with hundreds of entries.

One of the custom fields of this cpt is the 'movie-director' field. This is a single field that holds the director's name of the movie.

I now would like to create a dedicated custom post type for 'directors'. Each movie of this director should then be connected in a director-movie relationship to the director.

I have all the basics set up and I am aware of the field that holds the 'connection' info:
_wpcf_belongs_{parent-posttype-slug}_id

Question: how can I automatically create new entries in custom post types 'directors' from the existing single field 'movie-director' in the custom post type 'movies' and connect the newly created director to the existing movie that belongs to him?

I am looking for a way to avoid having to create and re-connect all movies by hand to a director. Any backend or frontend solution is greatly appreciated. I also own the plugin spreadsheet editor which allows me to bulk edit cpt entries in the backend.

Thx a lot for your help
Tobi

#1529571

I have all the basics set up and I am aware of the field that holds the 'connection' info:
_wpcf_belongs_{parent-posttype-slug}_id

This only works in the OLD relationships system. In the new relationships system, connection is not maintained by a custom field. Just want to be sure you are aware of this. If you have migrated to the new post relationships system this custom field will not work.

Question: how can I automatically create new entries in custom post types 'directors' from the existing single field 'movie-director' in the custom post type 'movies' and connect the newly created director to the existing movie that belongs to him?
There's nothing built-in to Toolset that will do this for you. You could export all the director names and import them as posts using a CSV file. Then if you want to use the old relationships system, you would have to then import that director ID as a custom field value for each Movie post to associate it with a director post. In the new relationships system, you would import posts with post relationships using a CSV file as shown here: https://toolset.com/documentation/user-guides/export-import/importing-content-from-csv-with-post-relationships/

Or you can use a custom PHP script that uses the post relationships API to connect posts programmatically.
https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/

#1534621

Thx Chris. I've tried the CSV way described in the link above, but I did not understand how to get my data to fit the prerequisites of th e CSV and how to import it correctly. The documentation lacks a step-by-step guide on how to do this. I've found int he meantime, that the WP Import plugin allows me also to connect relationships through their WP Types Add-on, but I've also hit a roadblock there, since the CSV has to be differently organised than the one I am having. I am trying to contact their support and will get back to you here once I know more. Thx! Tobias

#1536017

Okay understood. I will stand by for your update.