Last active
March 31, 2017 11:47
-
-
Save mohsinr/60de80e51b3fcf0c22956f5530281153 to your computer and use it in GitHub Desktop.
WordPress Move Meta data from OLD custom field Key to New key
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
# Inlcude in functions file for one time | |
# Remove after calling this function on some page one time | |
function warmarks_update_new_meta_from_old(){ | |
# Provide your custom values here: | |
$post_type = 'pdf'; //change it with your post type | |
$old_metaKey = 'ecpt_pdflink'; | |
$new_metaKey = '_jb_pdf'; | |
$args = array( 'posts_per_page' => -1, 'post_type' => $post_type ); | |
$posts = get_posts($args); | |
foreach ($posts as $post) { | |
# code... | |
$old_link = get_post_meta( $post->ID, $old_metaKey, true ); | |
$new_link = get_post_meta( $post->ID, $new_metaKey, true ); | |
if($old_link != '' && $new_link == ''){ | |
update_post_meta($post->ID, $new_metaKey, $old_link); | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment