Hi,
I am trying to import two spreadsheets as two separate, but related CPT's, and the two options that I have for connecting a related CPT is either by inputting the Post Title, or Post ID of the related post. Post Title is not possible to use for me since there are a bunch of Post Title's that are exactly the same wording and it will create anomalies, so I need to work with the Post ID.
My issue starts with the fact that I cannot obtain Post ID's before creating the Post itself. So I thought of a solution- I create a column called "ID" on the spreadsheet that uniquely identifies each row/post in the sheet (just like a Post ID, only it's a toolset custom field created by me).
My question is, if I import spreadsheet A with this extra column of "ID", is there a piece of code that can then take my custom made ID, and put it into the Post ID, and swap out the default ID that the Post is created with? This way, when I import spreadsheet B and want to connect them, I can simply use the "ID" column I created, because it will then be the actual Post ID's of spreadsheet A.
Thank You!
Hello,
There isn't such kind of built-in feature within Toolset plugins, see our document:
https://toolset.com/course-lesson/how-to-import-content-into-wordpress-using-csv/
Below two CVS importer plugins support Toolset post type replationship:
- WordPress Ultimate CSV Importer
- WP All Import – Toolset Types Add-On plugin
Both of them use other post's title to connect posts:
https://toolset.com/course-lesson/how-to-import-posts-from-csv-files-and-maintain-relationships-when-using-the-csv-importer-plugin/
https://toolset.com/course-lesson/import-posts-from-csv-with-relationships-using-wp-all-import/
In your case, you might consider custom codes, for example:
1) In your CSV file, add a custom field column "related-post-id", store the related post IDs
2) When you use CSV importer plugin to import data, use action hook "save_post" to trigger a custom PHP function:
https://developer.wordpress.org/reference/hooks/save_post/
3) In this PHP function, get the custom field "related-post-id" value:
https://developer.wordpress.org/reference/functions/get_post_meta/
And use it to related with other posts:
https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_connect_posts
My issue is resolved now. Thank you!