• Resolved toastiestudio

    (@toastiestudio)


    I have created a custom post type on my website and enabled post copy for it.
    I am able to copy a post, but any children of that post do not copy.
    I tested on a standard page, and there it works fine, it makes a copy of the page and its children.
    So seems somewhere copying children for custom post types isn’t working.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Enrico Battocchi

    (@lopo)

    Hi @toastiestudio,
    how did you create your custom post type? Did you write the code or did you use a plugin, and if so which one?

    Thread Starter toastiestudio

    (@toastiestudio)

    I wrote the code myself.

    This is the post type

    function create_resources_post_type() {
    	register_post_type( 'dcr-resources',
    		array(
    			'labels' => array(
    				'name' => _x( 'Resources', 'my_custom_post','custom' ),
            		'singular_name' => _x( 'Resource', 'my_custom_post', 'custom' ),
         	  		'add_new' => _x( 'Add New', 'my_custom_post', 'custom' ),
          			'add_new_item' => _x( 'Add New Resources Post', 'my_custom_post', 'custom' ),
            		'edit_item' => _x( 'Edit Resources Post', 'my_custom_post', 'custom' ),
            		'new_item' => _x( 'New Resources Post', 'my_custom_post', 'custom' ),
            		'view_item' => _x( 'View Resources Post', 'my_custom_post', 'custom' ),
            		'search_items' => _x( 'Search Resources Posts', 'my_custom_post', 'custom' ),
            		'not_found' => _x( 'No Resources Posts found', 'my_custom_post', 'custom' ),
            		'not_found_in_trash' => _x( 'No Resources Posts found in Trash', 'my_custom_post', 'custom' ),
            		'parent_item_colon' => _x( 'Parent Resources Post:', 'my_custom_post', 'custom' ),
            		'menu_name' => _x( 'Resources', 'my_custom_post', 'custom' ),
    			),
    			'description' => 'Resources Posts',
            	'supports' => array( 'title', 'editor', 'excerpt', 'thumbnail', 'revisions', 'custom-fields', 'page-attributes'),
    			'taxonomies' => array('dcr-resources_categories'),
    			'hierarchical' => false,
     			'public' => true,
    			'show_ui' => true,
    			'show_in_menu' => true,
    			'menu_position' => 25,
    			'menu_icon' => 'dashicons-carrot',
    			'can_export' => true,
    			'has_archive' => true,		
    			'exclude_from_search' => true,
    			'capability_type' => 'page',
    			'rewrite' => array('slug' => 'resources','with_front' => FALSE),
    		)
    	);
    }
    add_action( 'init', 'create_resources_post_type' );
    Thread Starter toastiestudio

    (@toastiestudio)

    After some more testing I found the issue!

    For a custom post type to clone children you need to have
    'exclude_from_search' => false,

    If set to true, it is excluded from ‘post_type’ => ‘any’

    • This reply was modified 7 years, 4 months ago by toastiestudio.
    Thread Starter toastiestudio

    (@toastiestudio)

    A fix for the plugin code that would still allow exclude_from_search to be true would be:

    line 495 duplicate-post-admin.php
    replace
    //$children = get_posts(array( 'post_type' => 'any', 'numberposts' => -1, 'post_status' => 'any', 'post_parent' => $post->ID ));
    with

    $duplicate_post_types_enabled = get_option('duplicate_post_types_enabled', array ('post', 'page'));
    	if(!is_array($duplicate_post_types_enabled)) $duplicate_post_types_enabled = array($duplicate_post_types_enabled);	
    	$childargs = array('numberposts' => -1, 'post_status' => 'any', 'post_parent' => $post->ID, 'post_type' => $duplicate_post_types_enabled);
    	
    	$children = get_posts($childargs);
    Plugin Author Enrico Battocchi

    (@lopo)

    Hi @toastiestudio,
    the fact is that my plugin is not duplicating the child posts because your custom post type is not hierarchical:
    'hierarchical' => false,

    From what I know, if you don’t set hierarchical to true and add page-attributes to supports, the UI won’t show any dropdown list to set the parent.
    So how did you manage to set the parent of the posts you’re trying to clone?

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Duplicating Custom Post Type Children’ is closed to new replies.