Navigation überspringen

[Gelöst] WP All Import / Two Tables relationship with ids

This support ticket is created vor 5 Jahren, 10 Monaten. 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
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

Dieses Thema enthält 7 Antworten, hat 2 Stimmen.

Zuletzt aktualisiert von Christian Cox vor 5 Jahren, 10 Monaten.

Assistiert von: Christian Cox.

Author
Artikel
#1229421

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

#1229428
#1229575

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

#1229578

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?

#1229584

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)?

#1229644
Screen Shot 2019-04-11 at 5.51.50 PM.png
Screen Shot 2019-04-11 at 5.40.38 PM.png

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).

#1229834

Ok, this is a bit complicated because I have 4500 organisations with 6500 departments. Could this be done with a SQL-Statement?

#1230590

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.