What I'm tiring, I've created a custom post-type called the recipe when creating a new post on the recipe, I have inserted a new post on another post-type it working fine but post created two times on every published post
function post_create_on_publish_only( $new_status, $old_status, $post ) {
if ( ( 'publish' === $new_status )
&& 'recipe' === $post->post_type
) {
$my_post = array(
'post_title' => get_the_title($post),
'post_status' => 'publish',
'post_type' => 'wpcf7_contact_form',
);
$get_post = get_page_by_title(get_the_title($post));
if ( !is_page($get_post->ID) && did_action( 'transition_post_status' ) === 1){
$id = wp_insert_post( $my_post );
}
}
}
add_action( 'transition_post_status', 'post_create_on_publish_only', 10, 3 );
How can I solve this issue? anyone can help me?