Reputation: 1488
Alright here is the problem... we have posts that are missing a custom field. We just recently received the values for that field.
Is there a way via phpmyadmin to insert in to the table post_meta a custom field named "translation" and then the value for each post already published?
I am trying to avoid having to go back to each post and adding this custom field one by one.
Thanks!
Upvotes: 0
Views: 2806
Reputation: 4146
Yes, it's doable ... but tricky. You'll have to run an INSERT
script on the wp_postmeta
table. Remember, the table has three columns: post_id
, meta_key
, and meta_value
.
So if you know the ID of the post and the meta value you want to set, you'd run the following query:
INSERT INTO `wp_postmeta` (post_id, meta_key, meta_value) VALUES (*ID*, 'translation', *VALUE*;
Where *ID*
is the id of the post you're attaching the value for and *VALUE*
is the meta value of the "translation" field.
Like I said, doable ... but you'll need a separate INSERT
query for each post. You could dump all of these into a single text file and run the entire set in one pass if you want, otherwise it might take as much time as it would to just add the key through the WordPress UI in the first place.
Upvotes: 2
Reputation: 23702
You can easily add the column with phpMyAdmin, but you're probably going to have the read the data with some sort of code and iterate through updating the values. PhpMyAdmin isn't really the best tool for importing data that's not already in .sql format.
Upvotes: 0