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 have two custom post meta objects that have been applied to all pages and posts in my sites. The names are MyCustomHeader and MyCustomTitle and I have one of these assigned to each post and page in my site.

I've just decided to change the names of these two meta objects so that they do not appear in the Custom Fields fieldset. I've done this by placing an underscore character before them. This changes the values to "_MyCustomHeader" and "_MyCustomTitle".

In order to account for the sites that have numerous references to the old post meta names, I need to create a routine that runs once (either in the form of a plugin or a script in my theme options that only executes on theme activation) that goes through the WP database and converts every value that was "MyCustomHeader to "_MyCustomHeader" and also "MyCustomTitle" to "_MyCustomTitle".

Any help much appreciated.

  • scott
share|improve this question

1 Answer 1

up vote 1 down vote accepted

You can run the following sql queries:

update wp_postmeta set meta_key=replace(meta_key,'MyCustomHeader','_MyCustomHeader') where meta_key like "MyCustomHeader";
update wp_postmeta set meta_key=replace(meta_key,'MyCustomTitle','_MyCustomTitle') where meta_key like "MyCustomTitle";
share|improve this answer
    
Thanks sorich. I think this will work, but I'm not sure how to run sql from functions.php. How do i grab a connection to the db? –  Scott B Sep 28 '10 at 20:06
    
Found it! $wpdb->query('query'); –  Scott B Sep 28 '10 at 20:24
    
You are welcome. –  sorich87 Sep 28 '10 at 20:46
    
Code is generating a fatal error when loaded as a plugin. Any ideas why? Are there external dependencies for "$wpdb->query when included as a plugin? –  Scott B Sep 28 '10 at 21:11
    
I replied on the other question. –  sorich87 Sep 29 '10 at 6:27

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.