Skip Navigation

[Resolved] Importing database content into Types

This support ticket is created 5 years, 6 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 5 replies, has 2 voices.

Last updated by Nigel 5 years, 6 months ago.

Assisted by: Nigel.

Author
Posts
#1120108

Hi,

I have a database with linked tables (ex: articles linked to an author and other tables).

Is it possible to import that (with WP ALL Import for example) AND keep the relationship in Types (ex: articles table has an author_id field (numeric) that points to the id of the author table... could it import for example "3" and when the author table is imported "know" that it is link to author "3" with First Name, Last Name, etc)?

If not, is it possible to just link Types to my existing database in any way, so we don't have to redo the data again? I.e. create a type and have the fields/custom fields linked to entries of the external db...?

#1120666

Nigel
Supporter

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

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

Hi Nelson

When importing data from non-WP sources you need to prepare the data so that it is in a suitable format to import, i.e. as a CSV file with the appropriate columns which, in this case will be used to maintain relationships when the data is imported.

A colleague of mine is working on this very issue at the moment, preparing a documentation page with a demonstration video about a use case which is similar to yours.

It will be published in a few days (announced on the blog), are you able to wait for that?

#1120760

Yes, my client has been trying for a while I think, so few days more shouldn't be an issue...

He said he tried the CSV way, but there was some formatting problems... That's why he went to WP All Import and XML...

We'll see after your blog post...

#1122388

I don't know if that is the post you were referring to, but that helped me understand: https://toolset.com/documentation/user-guides/how-to-import-content-into-wordpress-using-csv/how-to-import-data-from-a-csv-file-using-the-wp-all-import-toolset-types-add-on-plugin/post-relationships/

What I still don't get, though, is how to create those tables in the first place...

Ex: the example closest to the first step I need to accomplish is the one-to-many relationship example... I do understand how to import them and did it... BUT how do I create those CSV (or XML) files?

First, let's start with you example:
To produce those CSV files on export, I would need to have:
A table called Movies with 6 columns (Movie Name, ReleaseDate, Production Company, Shot In, Budget, Genre and Director), but we don't need the Director one for this example.
A table called Directors with 3 columns (Director Name, Director bio note, Date of birth).

Then you added to the CSV file 3 columns for 3 movies, 3 being the most a director can have... But when we have undreds of records, we can't manually created Movie 1, Movie 2... Movie 50 and copy all the data in them...

I might be limited in my SQL knowledge, but I didn't find a request that would allow me to export that kind of file... We can dynamically create rows, but not columns... I tried with joins and different things without success...

In my example, I have Articles with one Author (shoud be able to put many, but that's how it was built)... So, imported the Articles XML file, but now, I would need a way to create the Author file and have the title of the Articles (which serves as the unique key) in columns, but one has 137 articles... would make a lot of columns if I need to create them manually...

A query like that:
SELECT concat(AUT_PRENOM, ' ', AUT_NOM) AS NOM, AUT_NOTE, TITRE
FROM partageirbpi.pi_article inner join partageirbpi.pi_auteurs
ON pi_article.AUTEUR = pi_auteurs.AUT_ID;

returns, for example, 5 times the same author, with the same note, but a different title...

Any idea? I know the pro version of WP All Import support functions and loops... don't know if I need that (I guess so, later on, if I don't want to drag the title field 137 times)...

#1122401

With some tests I arrived with that query for your example:
SELECT directors.DirectorName, directors.DirectorBioNote, directors.DateOfBirth, (SELECT movies.MovieName FROM movies WHERE movies.Director = directors.iddirectors LIMIT 1) AS 'Movie 1', (SELECT movies.MovieName FROM movies WHERE movies.Director = directors.iddirectors LIMIT 1,1) AS 'Movie 2', (SELECT movies.MovieName FROM movies WHERE movies.Director = directors.iddirectors LIMIT 2,1) AS 'Movie 3'
FROM directors

But again, if we have 20, 50, 100 entries, this is not something that can be done manually...

#1123629

Nigel
Supporter

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

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

Hi Nelson

Sorry, the guide has not been published yet.

I prepared a PDF of the post draft which you can access here: hidden link

Can you read through it, and then if you are still stuck let me know and I will look over the details.

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