Viewing 2 replies - 1 through 2 (of 2 total)
  • Hey @ayrancd

    There are 2 options for duplicate post using duplicate page plugin

    1. Open All posts -> On hover on post there is “”Duplicate this”” option, click on it for duplicate post

    2. Open All posts -> Click on edit post which you want to duplicate -> in editor page there is “”Duplicate this”” option in right side above update button click on it to duplicate post

    You can also change its settings from, Duplicate page plugin tab -> setting ”

    Regards,

    Thread Starter Cezar Ayran

    (@ayrancd)

    @duplicatepagesupport you didn’t read my question. I needed a solution using PHP and I found it:

    function duplicatePost($post_id, $title, $block, $execution){
    	$post = get_post($post_id);
    	$args = array(
    	      'comment_status' => $post->comment_status,
    	      'ping_status'    => $post->ping_status,
    	      'post_author'    => $new_post_author,
    	      'post_content'   => $post->post_content,
    	      'post_excerpt'   => $post->post_excerpt,
    	      'post_name'      => $post->post_name,
    	      'post_parent'    => $post->post_parent,
    	      'post_password'  => $post->post_password,
    	      'post_status'    => 'draft',
    	      'post_title'     => $title,
    	      'post_type'      => $post->post_type,
    	      'to_ping'        => $post->to_ping,
    	      'menu_order'     => $post->menu_order
        	);
        	$new_post_id = wp_insert_post($args);
    
        	global $wpdb;
        	$post_meta_infos = $wpdb->get_results("SELECT meta_key, meta_value FROM ydo_postmeta WHERE post_id = $post_id");
     	if (count($post_meta_infos)!=0){
     		$sql_query = "INSERT INTO ydo_postmeta (post_id, meta_key, meta_value) ";
     		      foreach ($post_meta_infos as $meta_info) {
    	        		$meta_key = $meta_info->meta_key;
    	        		if( $meta_key == '_wp_old_slug' ) continue;
    	        		$meta_value = addslashes($meta_info->meta_value);
    	       		$sql_query_sel[]= "SELECT $new_post_id, '$meta_key', '$meta_value'";
    	     		}
    	     		$sql_query.= implode(" UNION ALL ", $sql_query_sel);
    	     		$wpdb->query($sql_query);
     	}
        	return $new_post_id;
    }

    We don’t nee a plugin to use it.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Calling plugin action using PHP’ is closed to new replies.