Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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?

share|improve this question
    
What is confusing or difficult about key/value metadata? –  s_ha_dum Nov 30 '12 at 4:25

1 Answer 1

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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