How can I import wordpress posts from a csv file into a database using phpmyadmin?
The problem is that there are so many posts with a lot of content. Tables in the csv file include title, content, post image, screenshots, slug, categories, tags and some custom fields (about 5 or 6).
Posts should be saved as drafts, and contents includes html code.
I have done a large csv import using phpmyadmin
Get the last post id from the (table-prefix)_post table and SET as @PostID.
Create a temp table and insert values.
Add post id into temp tables using AUTO_INCREMENT + @PostID , so you can add details into linked tables like (table-prefix)_postmeta table
Then inset data into the (table-prefix)_post table
Then add to any other tables
The fact that there are lots of posts, or that the posts have lots of content, really shouldn’t be a problem: that’s what bulk importing is for.
The HTML code in the posts also shouldn’t be an issue as long as the CSV is correct: it ought to have quoted the code so that it still parses correctly.
However, you’ll need to create an appropriate table with appropriate column types, so that you can import the data as it should be. The CSV won’t contain details about column types.
Most of the column types will probably be obvious, but you might want to think about using a type of
TEXT
(or evenLONGTEXT
) for the post content itself, if the posts can get very long.To import csv to MySQL we have Load Data Infile syntax. As the first answer conveys, you need to have table structure in accordance with the csv file you want to load, then the csv fileds are mapped with the table columns while you exec the command.
There is a blog post which explains different use-cases for importing CSV to MySQL you might want to refer (also check comments as well).
Hope this helps.