Duplicating existing WordPress pages, posts, or custom post types allows site managers to clone content templates quickly without rebuilding layouts manually.
Custom PHP Post Duplicator Function
// Duplicate post or page function in WordPress
function lynxbee_duplicate_post_as_draft() {
global $wpdb;
if (!isset($_GET['post'])) return;
$post_id = (int)$_GET['post'];
$post = get_post($post_id);
$args = array(
'post_title' => $post->post_title . ' (Copy)',
'post_content' => $post->post_content,
'post_status' => 'draft',
'post_type' => $post->post_type
);
wp_insert_post($args);
}
Comments and corrections