\n
\/*
\n* Function for post duplication. Dups appear as drafts. User is redirected to the edit screen
\n*\/
\nfunction rd_duplicate_post_as_draft(){
\nglobal $wpdb;
\nif (! ( isset( $_GET['post']) || isset( $_POST['post'])\u00a0 || ( isset($_REQUEST['action']) && 'rd_duplicate_post_as_draft' == $_REQUEST['action'] ) ) ) {
\nwp_die('No post to duplicate has been supplied!');
\n}
\n\/*
\n* Nonce verification
\n*\/
\nif ( !isset( $_GET['duplicate_nonce'] ) || !wp_verify_nonce( $_GET['duplicate_nonce'], basename( __FILE__ ) ) )
\nreturn;
\n\/*
\n* get the original post id
\n*\/
\n$post_id = (isset($_GET['post']) ? absint( $_GET['post'] ) : absint( $_POST['post'] ) );
\n\/*
\n* and all the original post data then
\n*\/
\n$post = get_post( $post_id );
\n\/*
\n* if you don't want current user to be the new post author,
\n* then change next couple of lines to this: $new_post_author = $post->post_author;
\n*\/
\n$current_user = wp_get_current_user();
\n$new_post_author = $current_user->ID;
\n\/*
\n* if post data exists, create the post duplicate
\n*\/
\nif (isset( $post ) && $post != null) {
\n\/*
\n* new post data array
\n*\/
\n$args = array(
\n'comment_status' => $post->comment_status,
\n'ping_status'\u00a0 \u00a0 => $post->ping_status,
\n'post_author'\u00a0 \u00a0 => $new_post_author,
\n'post_content' \u00a0 => $post->post_content,
\n'post_excerpt' \u00a0 => $post->post_excerpt,
\n'post_name'\u00a0 \u00a0 \u00a0 => $post->post_name,
\n'post_parent'\u00a0 \u00a0 => $post->post_parent,
\n'post_password'\u00a0 => $post->post_password,
\n'post_status'\u00a0 \u00a0 => 'draft',
\n'post_title' \u00a0 \u00a0 => $post->post_title,
\n'post_type'\u00a0 \u00a0 \u00a0 => $post->post_type,
\n'to_ping'\u00a0 \u00a0 \u00a0 \u00a0 => $post->to_ping,
\n'menu_order' \u00a0 \u00a0 => $post->menu_order
\n);
\n\/*
\n* insert the post by wp_insert_post() function
\n*\/
\n$new_post_id = wp_insert_post( $args );
\n\/*
\n* get all current post terms ad set them to the new post draft
\n*\/
\n$taxonomies = get_object_taxonomies($post->post_type); \/\/ returns array of taxonomy names for post type, ex array(\"category\", \"post_tag\");
\nforeach ($taxonomies as $taxonomy) {
\n$post_terms = wp_get_object_terms($post_id, $taxonomy, array('fields' => 'slugs'));
\nwp_set_object_terms($new_post_id, $post_terms, $taxonomy, false);
\n}
\n\/*
\n* duplicate all post meta just in two SQL queries
\n*\/
\n$post_meta_infos = $wpdb->get_results(\"SELECT meta_key, meta_value FROM $wpdb->postmeta WHERE post_id=$post_id\");
\nif (count($post_meta_infos)!=0) {
\n$sql_query = \"INSERT INTO $wpdb->postmeta (post_id, meta_key, meta_value) \";
\nforeach ($post_meta_infos as $meta_info) {
\n$meta_key = $meta_info->meta_key;
\nif( $meta_key == '_wp_old_slug' ) continue;
\n$meta_value = addslashes($meta_info->meta_value);
\n$sql_query_sel[]= \"SELECT $new_post_id, '$meta_key', '$meta_value'\";
\n}
\n$sql_query.= implode(\" UNION ALL \", $sql_query_sel);
\n$wpdb->query($sql_query);
\n}
\n\/*
\n* finally, redirect to the edit post screen for the new draft
\n*\/
\nwp_redirect( admin_url( 'post.php?action=edit&post=' . $new_post_id ) );
\nexit;
\n} else {
\nwp_die('Post creation failed, could not find original post: ' . $post_id);
\n}
\n}
\nadd_action( 'admin_action_rd_duplicate_post_as_draft', 'rd_duplicate_post_as_draft' );
\n\/*
\n* Add the duplicate link to action list for post_row_actions
\n*\/
\nfunction rd_duplicate_post_link( $actions, $post ) {
\nif (current_user_can('edit_posts')) {
\n$actions['duplicate'] = '<a href=\"' . wp_nonce_url('admin.php?action=rd_duplicate_post_as_draft&post=' . $post->ID, basename(__FILE__), 'duplicate_nonce' ) . '\" title=\"Duplicate this item\" rel=\"permalink\">Duplicate<\/a>';
\n}
\nreturn $actions;
\n}
\nadd_filter( 'page_row_actions', 'rd_duplicate_page_link', 10, 2 );<\/code><\/span><\/p>\n[You can use this code to duplicate post of your WordPress post by replacing the page with a post<\/strong> in the last two lines]<\/p>\n<\/span>Manual Copy Editor<\/strong><\/span><\/h2>\nThe manual copy editor method is the least method to recommended as it is a very time-consuming process. You have to copy the code of the individual page and then paste it to the new page you want to create.<\/p>\n
\n- Go to the page you want to duplicate.<\/li>\n
- On the toolbar, select code editor instead of visual text.<\/li>\n
- Then copy all the codes of the individual page.<\/li>\n
- Now open a new page and paste this code on the code editor of that page.<\/li>\n
- You can check whether the code is pasted properly or not by click on the visual text.<\/li>\n<\/ul>\n
<\/span>Conclusion<\/span><\/h2>\nAbove are some popular methods to duplicate a page in WordPress.\u00a0<\/strong>You can do this with or without plugins, but I recommend using plugins to save your time.<\/p>\nFurthermore, the plugin makes it easier to perform the task as you just need to click on the duplicate button. I hope you understand all the methods properly but if you have still any doubts then let me know.<\/p>\n<\/div>\n<\/div>\n<\/article>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"
Duplication of a WordPress page doesn’t mean copy it from elsewhere on the Internet, and doesn’t like stealing from somewhere. We are talking about duplicate a page in WordPress that you already owned. It can be done with the help of plugins as well as manually. Let’s discuss further why you need a duplicate page […]<\/p>\n","protected":false},"author":2,"featured_media":377,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[362],"tags":[384,378,381,370,363,375,372,374,379,367,376,380,366,371,364,365,382,387,386,369,385,377,368,373,383],"_links":{"self":[{"href":"https:\/\/basicwebguide.com\/wp-json\/wp\/v2\/posts\/366"}],"collection":[{"href":"https:\/\/basicwebguide.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/basicwebguide.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/basicwebguide.com\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/basicwebguide.com\/wp-json\/wp\/v2\/comments?post=366"}],"version-history":[{"count":0,"href":"https:\/\/basicwebguide.com\/wp-json\/wp\/v2\/posts\/366\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/basicwebguide.com\/wp-json\/wp\/v2\/media\/377"}],"wp:attachment":[{"href":"https:\/\/basicwebguide.com\/wp-json\/wp\/v2\/media?parent=366"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/basicwebguide.com\/wp-json\/wp\/v2\/categories?post=366"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/basicwebguide.com\/wp-json\/wp\/v2\/tags?post=366"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}