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 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?

share|improve this question
add comment

1 Answer

up vote 0 down vote accepted

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.

share|improve this answer
    
SELECT wp_posts.* is the only change to the query, just so you know. –  Dave Hunt Mar 19 '12 at 20:38
    
Thanks, unfortunately I have a duplicate key problem so I can't import. –  AlxVallejo Mar 19 '12 at 20:45
    
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 Mar 19 '12 at 21:41
add comment

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.