Last active
November 10, 2015 03:15
-
-
Save mintplugins/f6d7be7fb6d7ee6d98b2 to your computer and use it in GitHub Desktop.
Migrate Sermons
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 | |
//Paste this function into your theme's functions.php file to create a duplicate ctc_sermon for each mp_sermon | |
//Set the args for the new query | |
$mp_sermon = array( | |
'post_type' => "mp_sermon", | |
'posts_per_page' => -1, | |
'order' => 'ASC', | |
); | |
//Create new query for stacks | |
$mp_sermon_query = new WP_Query( apply_filters( 'mp_sermon', $mp_sermon ) ); | |
//Loop through the stack group | |
if ( $mp_sermon_query->have_posts() ) { | |
while( $mp_sermon_query->have_posts() ) : $mp_sermon_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 ); | |
//Get any Sermon Series | |
$mp_sermon_series = wp_get_post_terms( $post_id, 'mp_sermon_series', array("fields" => "names") ); | |
wp_set_object_terms( $new_ctc_sermon_post, $mp_sermon_series, 'ctc_sermon_series' ); | |
//Get any Sermon Speakers | |
$mp_sermon_speakers = wp_get_post_terms( $post_id, 'mp_preachers', array("fields" => "names") ); | |
wp_set_object_terms( $new_ctc_sermon_post, $mp_sermon_speakers, 'ctc_sermon_speaker' ); | |
//Get any Sermon Topics | |
$mp_sermon_topics = wp_get_post_terms( $post_id, 'mp_topics', array("fields" => "names") ); | |
wp_set_object_terms( $new_ctc_sermon_post, $mp_sermon_topics, 'ctc_sermon_topic' ); | |
//Get any books of the bible | |
$mp_bible_books = wp_get_post_terms( $post_id, 'mp_bible_books', array("fields" => "names") ); | |
wp_set_object_terms( $new_ctc_sermon_post, $mp_bible_books, 'ctc_sermon_book' ); | |
endwhile; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment