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 am converting a custom site to WordPress but I have a problem. I have about 20,000 posts for one Custom Post Type that has custom fields for both "source_name" and "source_url". Both these Custom Field Values need to be entered into the "wp_postmeta.meta_key" column for each article that has the custom field data. Each unit of custom field data also needs to be imported into the "wp_postmeta.meta_value" column. While every "post_id" is unique, both the "meta_key" and "meta_values" share the same "post_id".

I am working with SQL and CSV. Does anyone have insight into how I can get all this custom data into the wp_postmeta table correctly?

Thank you in advance!

share|improve this question
    
It's kind of hard to imagine what's going on - if you have 20,000 distinct posts/articles it seems unlikely these would all have the same post_id. Usually, when you import these into wp_posts they will be automatically be assigned unique ids since the id field autoincrements. I'd expect to then have to use these post_ids when importing your custom field data into wp_postmeta. –  Jon Jul 29 '13 at 18:18
    
Thanks for your reply Jon. My post was unclear on the point you raise. Sorry about that! The post_id's are okay. I have edited it to clarify that both the "meta_key" and "meta_values" share the same "wp_postmeta.post_id". I mention this as it is one of the things that is making it difficult for me to run a simple JOIN statement. So, I'm kinda confused as to how to get all the data into that table... –  user2591811 Jul 29 '13 at 18:24
    
Right I think I understand. Have you imported the posts already? How did you do that? If you're using phpMyAdmin or similar you could export these to a csv and get the post_ids for each article. Would anything stop you from matching these ids to each pair of meta keys and values? –  Jon Jul 29 '13 at 18:28
    
Example: you have an article "test" with custom fields name="X" and URL="X.com". You import test into into wp_posts. You export it and find it has ID 1234. You can then create a CSV with 2 rows: ,1234,name,x and ,1234,url,x.com, which you import into wp_postmeta. Unless I'm missing something :-) –  Jon Jul 29 '13 at 18:32
    
Yes, I've already imported the posts. I did that by uploading the SQL dump from the old custom site to the same database as my new WP site and then moving the required data via SQL/phpMyAdmin into the WP tables (the data sets were so large they were crashing my csv files so working in the database was quicker). I may be able to match the ids to the meta keys and values as you suggest. Just interacting here has helped me process it in my own head. So I will try and see how far I get. I'll report my findings... Thanks! –  user2591811 Jul 29 '13 at 18:41

Your Answer

 
discard

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

Browse other questions tagged or ask your own question.