1

I'm migrating data from a totally different database style into WP. The main issue I'm trying to wrap my head around is how to import any meta data, given that WP uses a key value pair style for meta tables.

Is there a way to import column data as key value pairs?

1
  • What is confusing or difficult about key/value metadata? Commented Nov 30, 2012 at 4:25

1 Answer 1

0

You should wirte a Function or Plugin inside WordPress to achive that.

First, you could insert the tables into your WordPress Database.

After that, make sure you make good use of the WordPress postsstructure. Set up a Loop through your existing Posts that you want to import.

At each Post create a WordPress Post using wp_insert_post(). This Function returns the ID of your new Post.

Every bit of Metadata that you want to add to your Post is added afterwards. It would be like this:

foreach ( $existingposts as $existingpost ) {

    $newPostData['post_date'] = $existingpost['post_date'];
    // and so on, make sure to populate all the fields except the ID parameter, as this one is given by WordPress

    $newPostID = wp_insert_post( $newPostData );

    add_post_meta( $newPostID, '_firstPostMeta', $existingpost['firstPostMeta'] );
    // and so on, every Meta at a time

}

Be sure to test your function before looping it through all the posts at once. You may want to divide your stack of existing posts into groups of 20 or 50, depending what your server is capable to do, to avoid inconsitensies due to server timeout.

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.