I need to take the post meta from a post, and create a custom post type post. I'm using the code below but think it's creating an infinite loop.
When wp_insert_post fires I have create_cptpost function execute which gets the PID of the post created $post_id
gets a custom field ac_1
then I need to create a new post in the cpt post type and update the post meta. Is there another way to do this? I'm basically trying to copy the first normal post content to a new custom post type post.
function create_mycpt( $post_id ) {
$post = get_post($post_id, ARRAY_A);
if ( wp_is_post_revision( $post_id ) )
return;
$ac1 = get_field('ac_1',$post_id);
$my_post = array(
'post_title' => 'The title',
'post_type' => 'mycpt'
);
$pid = wp_insert_post( $my_post );
update_post_meta($pid, 'ac_1', $ac1);
}
add_action( 'wp_insert_post', 'create_mycpt' );