Skip Navigation

[Resolved] Child relationship during import

This support ticket is created 7 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
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+01:00)

This topic contains 1 reply, has 2 voices.

Last updated by Nigel 7 years, 7 months ago.

Assisted by: Nigel.

Author
Posts
#488797

OK so my question here is a continuation of the following post.

https://toolset.com/forums/topic/post-relationships-for-imported-data/

Basically I have a big csv. Each line is basically like the following. (over simplified on purpose)

Company name, company address, company website, contact name, contact email, contact phone

if a company has 10 contacts I will have 10 lines on my csv. The first 3 fields will be duplicate and the next 3 will be the next contact info.

What I am looking to do is the following

Parent = Company Name, Company Address, Company Website
Child = Contact 1 name, Contact 1 email, contact 1 phone
Child = Contact 2 name, Contact 2 email, contact 2 phone
all the way up to 10

I realize from what I have read here you use the parent post ID number to associate the child post to it for importing.If I had 50 of these to do this with it would be fine. I have about 9K to do.

Is there a way to possibly import all the parents in. Then pull them all back out so the csv still has the same number of lines but now has the post ID too? Then maybe paste all the children in so it all lines up again? Will it stay in order? Any better ideas to accomplish this?

Ted

#488933

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+01:00)

Hi Ted

Just so we are on the same page, the reason this is difficult is because child posts are associated with parent posts by storing the id of the parent post as a custom field ('_wpcf_belongs_parent-slug_id'). When you import posts the post id is created on the fly and is not known—and cannot be known—in advance.

Depending on what you are using for the import, when no post id is supplied the post is deemed to be new and a new post created, but if the post id is supplied then you are deemed to be updating an existing post.

So, yes, one option is to import all of the data to create the posts. Then export the data, only bothering to export the minimum fields required when doing an import. You can then add a column for the custom field _wpcf_belongs_parent-slug_id and, with a lot of copying and pasting, add the id of the parent post row to the child rows. Then re-import the data.

For 9k posts that is quite a lot of manual editing, but would still be much easier than doing the equivalent in the WordPress admin pages.

An alternative would be to run a batch job in WordPress to automate the process.

However, there must be something in the data you import that uniquely connects the child posts to the parent posts so that your batch process can identify the post relationships.

If the parent post titles are unique, for example, you could add a column for a temporary custom field on the child posts that will store the title of the parent post. If you can re-export your data from its original source in such a format then, great, otherwise you are just exchanging one lot of manual copying and pasting from the first solution (the post ids) for another (the post titles).

If you can re-organise your source data in such a way that the child posts are related in some unique way to the parents (or if some such relationship already exists) then the batch job would be the best option. I can't write it for you, but if you want to go down that route then let me know and I will give you some pointers.

This ticket is now closed. If you're a Toolset client and need related help, please open a new support ticket.