Skip Navigation

[Resolved] Import csv with post relationships of two custom post types

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
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9: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/Karachi (GMT+05:00)

Author
Posts
#2537329
relationship in a product with different stores.PNG

Hello, I have a website that has products in woocommerce and those products are related to other post of a custom post type of stores. This custom post type stores has custom fields. Many to many relationship.

I would like to know if you can import through a csv, the relationships and custom fields between products and stores to not have to do it manually. If it can be done, how should I do it? is there a step by step?

Best regards and thanks

#2537675

Hi,

Thank you for contacting us and I'd be happy to assist.

It is possible to import the custom posts, custom fields, and the post-relationships data through a CSV file.

There are a number of CSV import plugins that can be used for this and here are some useful guides on this topic:

https://toolset.com/course-lesson/how-to-import-content-into-wordpress-using-csv/
https://toolset.com/course-lesson/importing-content-from-csv-with-post-relationships/
https://toolset.com/course-lesson/how-to-import-posts-from-csv-files-and-maintain-relationships-when-using-the-csv-importer-plugin/
https://toolset.com/related-lesson/export-import/

I hope this helps and please let me know if you need further assistance.

regards,
Waqar

#2538399
relationship custom field.PNG
toolset import-export associations.PNG

Hi Waqar, thanks for the information but in no documentation does it explain what I want to do. Maybe I have not explained my need well.

I need to import a cvs that relates woocommerce products with a stores CPT. In this relationship there is a custom field of type URL to be filled in when importing the relationships (screenshot: relationship custom field).

I want to import using Toolset tool (screenshot: toolset import-export associations).

How can I do the import with Toolset? I have not found any documentation or video tutorials about it.

Best regards and thank you

#2540491

Thanks for writing back.

To suggest more specific steps for this import, I'll need to see how these post types and the involved custom fields are set up in the admin area.

Can you please share temporary admin login details, along with the example CSV file that you've tried to use?

Note: Your next reply will be private and making a complete backup copy is recommended before sharing the access details.

#2544883

Thank you for sharing the details.

I've performed a number of tests on my website with the 'WP All Import' plugin, but couldn't make an import like this work.

Here is a workaround that I'll recommend that will involve some extra steps and custom code:

1. As the product posts are already there, the first step will be to import the "Online Platforms" posts, as simple regular posts, without any post-relationship information.

2. Once these posts have been imported, you can register a temporary post type 'Temp' and add three single line type custom fields to this post type:

- WooCommerce Products
- Online Platforms
- URL Exacta del Producto

3. Next, you'll create a CSV file for the import of posts into this new post type, so that each post will have the title of the relevant 'WooCommerce Products' post in the 'WooCommerce Products' field, title of the relevant 'Online Platforms' post in the 'Online Platforms' field and the common URL for their connection in the 'URL Exacta del Producto' field.
( it doesn't matter what the title of these posts is as they're only temporary )

4. Import this CSV file into this new post type and now you'll have a record of each post connection with the 'WooCommerce Products', 'Online Platforms', and the 'URL Exacta del Producto' stored as a separate post.

5. The last step would be to create a custom code, that will
- loop through each post in this 'Temp' post type,
- extract the titles of the relevant product and online platform post from the custom field,
- get the IDs of those participating posts and then join them in the relationship, using the "toolset_connect_posts" function:
https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_connect_posts
- this function also returns the ID of the resulting 'intermediary' post. You can use that ID to store the "URL Exacta del Producto" value from the current temporary post in the loop to the actual 'intermediary' post.

6. Once the relationship connections have been successfully created and the custom field data has also been updated, you can delete the posts in the 'Temp' post type and then also delete this post type.

I hope this makes sense and please let me know if you have any follow-up questions.