Posted on September 25, 2008 | Categories: Technology
I have thousands of HTML pages that need to be updated – I just have to swap a couple of lines. I was wondering how to do it all at once and in subdirectories as well.
Here’s what worked:
for mFile in `find . ! -type d -name ‘*.html’` do
sed -i ‘s/text1/replacement1/g’ $mFile
sed -i ‘s/text2/replacement2/g’ $mFile
sed -i ‘s/text3/replacement3/g’ $mFile
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.