I have a MySQL table with about 500 rows of entries each containing: title, author, series, and series number.

Would anyone know how to mass convert the data into (1 entry per post) custom post type with title becoming post title, author and series as separate custom hierarchical taxonomies, and series number as a custom meta?

I'm planning to change from a simple MySQL database management system into a site in a WP MS installation.

  • 3
    post the table structure, maybe someone can help you with a code snippet Jun 23, 2011 at 18:31
  • @OneTrickPony The table only has 4 fields: Title, Author, SeriesName and SeriesNum. The first 3 fields are type varchar(255) and SeriesNum is int(255). If there's anything else you need to know, ask.
    – OTN
    Jun 24, 2011 at 8:38

2 Answers 2


You can use the following method :

  1. Export your SQL data and make a CSV file out of it
  2. Parse that CSV file in a PHP script and put the data into an array
  3. Parse the array and for each row, insert the values into WP

You will need the following functions to insert the data into WP :

  1. wp_insert_post() to create and insert post data (title, content, etc.)
  2. wp_insert_term() to create the taxonomies terms and wp_set_post_terms() to set them for each post
  3. update_post_meta() to insert the custom field data of your posts

I suggest before doing all that you register the custom post type and taxonomies you are going to use in WP.

  • 4
    SQL to CSV to PHP seems unnecessary, just select the data from the source database and loop over the results, inserting each record straight into WP.
    – Milo
    Jun 23, 2011 at 18:42
  • @Milo, yes you're right. SQL->CSV export may only be useful if the new site is on a different server and remote connect is not possible.
    – mike23
    Jun 23, 2011 at 18:47
  • Sorry, I'm no good at coding such things. It goes way beyond my meager PHP "skills". Would it be possible for you to lend a hand on details?
    – OTN
    Jun 24, 2011 at 8:41

Quick tips, as mike23 suggest export the table as CSV, the use the plugin CSV Importer to import data back in wp. Read the docs on the plugins page.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.