0

I'm operating on two WordPress sites and I need to export posts only with a specific custom field from one site and import into the other. I can't do a generic dump of the database because some data would be overridden.

My SQL query:

SELECT * FROM wp_posts INNER JOIN wp_postmeta ON wp_postmeta.post_ID = wp_posts.ID WHERE ( wp_postmeta.meta_key = 'Color' AND wp_postmeta.meta_value IS NOT NULL );

Now I can export that into a .xml or .csv but I can't import that into the other site.

This is because the meta columns are appended to the row of the wp_posts. (Screenshot: http://screencast.com/t/bjogBFYyoL)

Is there a work-around?

1 Answer 1

1

Change your query to:

SELECT wp_posts.* FROM wp_posts INNER JOIN wp_postmeta ON wp_postmeta.post_ID = wp_posts.ID WHERE ( wp_postmeta.meta_key = 'Color' AND wp_postmeta.meta_value IS NOT NULL );

That way it only gets the data in wp_posts, but still filters based on your criteria.

3
  • SELECT wp_posts.* is the only change to the query, just so you know.
    – Dave Hunt
    Commented Mar 19, 2012 at 20:38
  • Thanks, unfortunately I have a duplicate key problem so I can't import.
    – AlxVallejo
    Commented Mar 19, 2012 at 20:45
  • 1
    You can fix that by writing out all of the individual columns in the wp_posts table, except for the ID column. For example: SELECT wp_posts.post_author, wp_posts.post_date, wp_posts.post_date_gmt, wp_posts.post_content, wp_posts.post_title, etc, etc...
    – Dave Hunt
    Commented Mar 19, 2012 at 21:41

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.