• Resolved MT

    (@micheletenaglia)


    I am trying to clone a custom post type without saving the post parent but tgis doesn’t seem to be an option. I have tried to disable the option “children” in plugin options with no luck. I ahve also tried some of the filters that I have found in the documentation of this plugin but there’s only one filter in which the new post ID is available. I have made a test using the ID and wp_insert_post but still no result, the post parent keeps being saved. Is there anything I am missing or what I am trying to do is not possible?

Viewing 1 replies (of 1 total)
  • Thread Starter MT

    (@micheletenaglia)

    I have found a way to remove the post_parent using a form and a custom function. If anyone has the same problem here’s what I have done.

    function custom_duplicate_post_create_duplicate() {

    if( !isset($_GET['custom_clone_id']) || empty($_GET['custom_clone_id']) ) {
        return;
    }
    $post_id = sanitize_text_field($_GET['custom_clone_id']);
    
    $status = 'draft';
    if( isset($_GET['custom_clone_status']) && !empty($_GET['custom_clone_status']) ) {
        $status = sanitize_text_field($_GET['custom_clone_status']);
    }
    
    $parent_id = 0;
    if( isset($_GET['custom_clone_parent_id']) && !empty($_GET['custom_clone_parent_id']) ) {
        $parent_id = sanitize_text_field($_GET['custom_clone_parent_id']);
    }
    
    $post = get_post( $post_id );
    unset( $post->post_parent );
    $post->post_parent = 0;
    
    $new_post_id = duplicate_post_create_duplicate( $post, $status, $parent_id );
    
    $url = get_edit_post_link( $new_post_id );
    
    wp_safe_redirect( $url );
    exit;

    }
    add_action(‘wp_loaded’,’custom_duplicate_post_create_duplicate’);

Viewing 1 replies (of 1 total)

The topic ‘Post parent’ is closed to new replies.