Hello,
I want to import two tables which have a one to many relationship. It is defined with ids.
the first table has an id. the second one has an pid.
Author: id | name | ...
Book: id | pid | title | ...
I do not understand how to import this, using wp all import (with toolset addon) and have the relationship.
Best wishes
Daniel
Hi Christian,
I read the example several times and tried to import it several ways, but always with the wrong results. Importing itself worked fine with more than 5000 sets.
In the example it uses the posttitle to connect the relationship. But I can't use the title. There are the different IDs which connect the two in the original database. The IDs are not the wordpress post-ids?
Best, Daniel
There are the different IDs which connect the two in the original database. The IDs are not the wordpress post-ids?
I don't really understand what this means, sorry! What is 'pid' in the Book post? Is it the corresponding Author post ID? If not, what is it, and how is it connected to the Author's post ID?
I'll try to explain again 🙂 Sorry.
I have a CSV/XML file called "Organisations":
oid | Name Of The Organisation | and others
I have a second file called "Departments":
did | pid | Name of the Department | and others
"pid" has the value from "oid" in the parent post.
So the connection should be made on 1 (oid) to many (did)?
Yes, this sounds like one (Organization) to many (Departments). The format required to import these posts is a bit different from what you have now. If you download the files Directors.csv and Movies.csv, you can see the format required. You need this format:
Organizations.csv:
- OID, Name of the Organization, [other fields], DID1, DID2, DID3, DID4, ...etc. for as many Departments as possible
Departments.csv:
- DID, Name of Department, [other fields]
I'm attaching a screenshot here with some notes for you to review. Notice how I added a column for the Movie ID, which isn't present in the original Movies.csv file. This is required since you are not using Titles. You must use this as the unique identifier in WP All Import (see the screenshot).
Ok, this is a bit complicated because I have 4500 organisations with 6500 departments. Could this be done with a SQL-Statement?
Possibly, but custom SQL support isn't offered here in the forums. On the other hand I can help you use any of our PHP APIs, including the post relationships API: https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/
To use the API to connect two posts, you need to loop over the posts and their related post IDs using PHP. To do that, you will have to write a script that reads your existing CSV information and parses the related posts, then uses the correct APIs to import the posts and also relate the posts. In my opinion, it's more work than writing a script to parse the CSV file and create a new CSV in the required format. Then let the import tool do the rest of the work.