function lp_duplicate_post_save_as_new_post($status = '') { /* Get the original post */ $id = isset($_GET['post']) ? $_GET['post'] : $_POST['post']; $post = get_post($id); /* Copy the post and insert it */ if (isset($post) && $post != null) { $new_id = lp_duplicate_post_create_duplicate($post, $status); if ($status == '') { /* Redirect to the post list screen */ wp_redirect(admin_url('edit.php?post_type=' . $post->post_type)); } else { /* Redirect to the edit screen for the new draft post */ wp_redirect(admin_url('post.php?action=edit&post=' . $new_id)); } exit; } else { $post_type_obj = get_post_type_object($post->post_type); wp_die(esc_attr(__('Copy creation failed, could not find original:', 'landing-pages')) . ' ' . $id); } }
function lp_duplicate_post_copy_children($new_id, $post) { /* get children */ $children = get_posts(array('post_type' => 'any', 'numberposts' => -1, 'post_status' => 'any', 'post_parent' => $post->ID)); /* clone old attachments */ foreach ($children as $child) { lp_duplicate_post_create_duplicate($child, '', $new_id); } }