• I am looking for a plugin to duplicate and rename a custom field in the entire site. Do you know any plugin that can do this?

Viewing 8 replies - 1 through 8 (of 8 total)
  • Could use phpMyadmin for something like that, but backup your database first!

    This will update all records where meta_key is ‘oldvalue’ and replace it with ‘newvalue’

    UPDATE wp_postmeta SET meta_key='newvalue' WHERE meta_key='oldvalue' ;

    Of course use the correct table name for your postmeta table if it is not wp_postmeta, and replace newvalue and oldvalue as appropriate.

    Thread Starter bluebird2

    (@bluebird2)

    Thanks, but I don’t want to replace the older names with new names. I need to create new custom fileds that copy the “value” of the old custom field and save them automatically without me being involved.

    This seems to work:

    INSERT INTO wp_postmeta (post_id, meta_key, meta_value)(
    SELECT post_id, 'newkey', meta_value
    FROM wp_postmeta
    WHERE meta_key='oldkey'
    )

    Thread Starter bluebird2

    (@bluebird2)

    Thanks.

    Oops, I forgot to warn you to backup your database before proceeding!

    Can I adda question??? How could I use some SQL to change thr PREFIX of my custom fields? e.g. vom “pd_cf_xyz” to “cf_xyz”, where xyz is along list of different values…. So I assuem some regex woudl be needed?

    Regarding…

    INSERT INTO wp_postmeta (post_id, meta_key, meta_value)(
    SELECT post_id, 'newkey', meta_value
    FROM wp_postmeta
    WHERE meta_key='oldkey'
    )

    1. Does this copy to the other field within the same post?

    2. The above is within the same table. How would you copy the value from two different tables. Eg. from the post_content to the meta?

    Thanks!

    Alrighty. Figured it out. Rather then approaching it with MySQL, went the PHP route.

    <?php query_posts("showposts=-1&offset=0&category_name=audio"); ?>
    	<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    
    	<?php update_post_meta(get_the_ID(), 'event', get_the_time('Y-m-d H:i:s')); ?>
    	<?php update_post_meta(get_the_ID(), 'audio_url', get_the_content()); ?>
    	<?php update_post_meta(get_the_ID(), 'speaker', get_the_author()); ?>
    
    	<?php endwhile; ?>
    	<?php endif; ?>
    <?php wp_reset_query(); ?>
Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘A plugin to Duplicate and Rename a Custom Field’ is closed to new replies.