Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mintplugins/9e8127870112cb994578 to your computer and use it in GitHub Desktop.
Save mintplugins/9e8127870112cb994578 to your computer and use it in GitHub Desktop.
<?php
//Paste this function into your theme's functions.php file to create a duplicate ctc_sermon for each old sermon
function mp_migrate_ezekiel_sermons(){
if ( !isset( $_GET['duplicate_sermons'] ) ){
return;
}
//Set the args for the new query
$cpt_sermons = array(
'post_type' => "cpt_sermons",
'posts_per_page' => -1,
'order' => 'ASC',
);
//Create new query for stacks
$cpt_sermons_query = new WP_Query( $cpt_sermons );
//Loop through the stack group
if ( $cpt_sermons_query->have_posts() ) {
while( $cpt_sermons_query->have_posts() ) : $cpt_sermons_query->the_post();
$post_id = get_the_ID();
$post_itself = get_post( $post_id );
//For our new post, change the Post Type to ctc_sermon
$post_itself->post_type = 'ctc_sermon';
//remove the ID so that it creates a new one
unset( $post_itself->ID );
//Create a Duplicate of this post as a ctc_sermon
$new_ctc_sermon_post = wp_insert_post( $post_itself, true );
//OLD Sermon Video
$sermonvideo = get_post_meta( $post_id, 'sermonvideo', true );
//Set the Video file in the new one
update_post_meta( $new_ctc_sermon_post, '_ctc_sermon_video', $sermonvideo );
//Get the audio file from the old post
$audio_value = get_post_meta( $post_id, 'sermonmp3', true );
//Set the audio file in the new one
update_post_meta( $new_ctc_sermon_post, '_ctc_sermon_audio', $audio_value );
//Get the sermon author
$sermonauthors = array();
$sermonauthors[] = get_post_meta( $post_id, 'sermonauthor', true );
//Get any Sermon Speakers
$term_taxonomy_ids = wp_set_object_terms( $new_ctc_sermon_post, $sermonauthors, 'ctc_sermon_speaker' );
if ( is_wp_error( $term_taxonomy_ids ) ) {
print_r( $term_taxonomy_ids );
die();
}
//Set the thumbnail
$post_thumbnail_id = get_post_thumbnail_id( $post_id );
update_post_meta( $new_ctc_sermon_post, '_thumbnail_id', $post_thumbnail_id );
endwhile;
}
}
add_action( 'admin_init', 'mp_migrate_ezekiel_sermons' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment