Skip Navigation

[Resolved] creating csv file to import post relationships

This support ticket is created 5 years, 5 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
- 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)

This topic contains 6 replies, has 2 voices.

Last updated by Waqar 5 years, 5 months ago.

Assisted by: Waqar.

Author
Posts
#1297301
relationship.JPG
relationship-csv.JPG

Hi Nigel,
I have 2 post types - plant and (medical) complaint all posts already exist.
Every complaint is treated by one or more of the plants, I now need to import a csv file to create the relationship / association so I can display the plants with the complaints they're used to treat.
The screenshots show an example of existing posts. I'm using the free csv importer plugin.
Very much appreciate if you could show me the correct csv and column headings for the posts in the attached example - I'd prefer to use the post id instead of post title if possible.
I also posted this on a closed thread that you answered (5 months ago), posted again here 'case I wasn't sure you'd pick it up from there.
Thanks for your help
David

ps. Don't understand why I'm only given 2 options:
1. Anyone from the support team can help me
2.I prefer to get help from another support person and not Nigel

I'd like you to answer if possible

#1298203

Hi David,

Thank you for waiting and I apologize for the delay.

I've been performing some tests to make this import work through Post ID (instead of Titles) and this has taken more time than I initially expected.

But, I'm close in completing this and will share a detailed update shortly, within the next two hours at maximum.

Thank you for your patience.

regards,
Waqar

#1298235

Hi David,

Thank you for waiting again. I've completed the tests and here are my findings:

1. The way Toolset's import association feature works, it can only pick up relations through the post titles and not the IDs.
( some of the workarounds that I've tested weren't successful )

2. Here is an example CSV file that can be used to import the posts and the relationship data that you've shared in your screenshot:
hidden link

Note: Please make sure that it is using the correct spellings of slugs that are used on your website for post types and the post-relationship.

3. If you've have already added the Plant and Complaint posts on your website, using the "CSV Importer" plugin ( https://wordpress.org/plugins/csv-importer/ ) will result in duplicate posts, since it doesn't include a feature to only update existing post data or check for duplicates.

To overcome this you have two options, and you can choose depending on the number of posts that you're dealing with:

1. To continue using this free "CSV Importer" plugin, you'll first have to delete all the existing Plant and Complaint posts and then run the importer.

OR

2. If you'd like to avoid option 1, you'll need a Pro version of a more advanced CSV importer plugin like "WP Ultimate CSV Importer", which does allow posts update feature, and will ensure that these posts are not added as duplicates.

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

regards,
Waqar

#1298295
associations.JPG

Hi Waqar,
Thanks for taking the time to investigate this.
I was also working on this and was following this link
https://toolset.com/documentation/user-guides/importing-content-from-csv-with-post-relationships/
where I understand using Toolset Export/Import > Import Associations you can upload just the relationships, according to this document I created the attached csv example associations.jpg.
According to what you say I'd need to replace the id's with the post title.
I understood that there are in fact 3 separate files the parent posts, the child posts and the relationships. Is this not correct?
If I use your example I'd have to add the toolset associations info to the child posts, so wouldn't it be enough to just reload the complaints (child) posts without reloading the plant (parent posts)?
One other question at what point do I use Toolset Export/Import > Import Associations?

#1298545

Hi David,

Thanks for writing back.

I'll be happy to explain step-by-step, how the import of data using the example file that I shared will work. This will help you understand the process better and will also answer your questions.

First, let's break the file into two virtual steps, for better understanding:

1. The step that imports the "Plant" posts:
( screenshot: hidden link )

At this stage, only the parent "Plant" posts will be imported and we don't need to pass on any data for the sake of post-relationship.

2. The step that imports the "complaint" posts:
( screenshot: hidden link )

At this stage, the child "complaint" posts will be imported, but with child posts, we will need to also pass on the title of the parent post, for joining them in a post-relationship.

Notes:

a). It is your choice, whether you'd like to perform the above steps, through a single file (like my example) or through two separate files ( one for the data of each step ).

b). Your observation is correct and if you've already imported the "Plant" posts, then you don't need to import them again ( since no relationship data needs to be set with the parent posts ).

c). At this point, the import process will add the parent post's title in a hidden field "_toolset_associations_plant-with-complaint-list" with each "complaint" post, however, this doesn't mean that the post-relationship has been established.

3. The step that actually establishes the post-relationship between the imported posts:

When you'll go to WP Admin -> Toolset -> Export / Import -> Associations (tab), you'll see all the detected post-relationship references, as a result of the import process.
( example screenshot: hidden link )

In the background, the plugin will check all the child posts for a hidden field "_toolset_associations_plant-with-complaint-list" and for the posts where a title of parent Plant post will be available, it will show that the relationship can be formed between them. When you'll click the "Start Import" button on this screen, only then the post-relationship will get established between the imported posts.

I hope this makes it more clear.

regards,
Waqar

#1298607

Thanks Waqar, for the detailed explanation, much appreciated.
One of my problems is I don't have the original csv of the complaint posts, and it's alot of work preparing the complaints for upload, so my plan is to download the complaint posts in csv format, delete the complaint posts from the site, add _toolset_associations_plant-with-complaint-list column with the plant post title to the downloaded complaint posts and then upload them as new posts. Does this sound like a workable plan to you?

Thanks for your help
David

#1299147

Hi David,

You're very welcome and glad that my message helped.

Your understanding is correct and these are the exact same steps that I would take in this situation.

This ticket is still open if you need any further assistance around what we've discussed.

For a different question or concern, you're welcome to start a new ticket.

regards,
Waqar