Posted on September 23, 2008 | Categories: Technology
If most of the pages have the same custom field values and need to be updated, going through each page manually would take long time.
This can be done by running an update query directly to the database. This should be done carefully, of course.
1) Make a backup of the database.
2) Custom fields are stored in the “wp_postmeta” table and marked with the meta keys. We need the field called “facts”, so we’ll be looking for that key.
3) Select pages that will need to have facts changed. Query:
WHERE meta_key = ‘facts’
AND post_id NOT
IN ( 10, 643, 316, 532)
Note that “post_id not in” clause will exclude those posts/pages, and the custom fields won’t be updated for those pages.
4) Update query:
update `wp_postmeta` set meta_value = ‘new_meta_value_goes_here’ WHERE meta_key = ‘facts’
and post_id not in (10,643,316,532)
5) Check that everything worked fine.