• Resolved lynkei

    (@lynkei)


    Hello,
    I have two custom post types: Category and Product

    What I want to do is select Category pages as the parent for Product pages. Is this possible? The code that I’m using to register these is the following.

    /* Category Post Type */
        add_action('init', 'Category_post_type_init');
        function Category_post_type_init() {
          $labels = array(
            'name' => _x('Category', 'post type general name'),
            'parent_item_colon' => __('Category'),
                'parent' => __('Category'),
          );
          $args = array(
            'labels' => $labels,
            'public' => true,
            'publicly_queryable' => true,
            'show_ui' => true, //false - to hide from the admin area menu
            'rewrite' => true,
            'query_var' => true,
            'capability_type' => 'post',
            'hierarchical' => true, //allow parent pages
            'show_in_nav_menus' => false,
            'menu_position' => 1000,
            'supports' => array(
              'title',
                  'page-attributes'
            )
          );
          register_post_type('Category',$args);
        }
    
        /* Product Post Type */
        add_action('init', 'Product_post_type_init');
        function Product_post_type_init() {
          $labels = array(
            'name' => _x('Product', 'post type general name'),
            'singular_name' => _x('Product', 'post type singular name'),
            'add_new' => _x('Add New', 'Product'),
            'add_new_item' => __('Add New Product'),
            'edit_item' => __('Edit Product'),
            'new_item' => __('New Product'),
            'view_item' => __('View Product'),
            'search_items' => __('Search Products'),
            'not_found' =>  __('No Products found'),
            'not_found_in_trash' => __('No Products found in Trash'),
          );
          $args = array(
            'labels' => $labels,
            'public' => true,
            'publicly_queryable' => true,
            'show_ui' => true, //false - to hide from the admin area menu
            'rewrite' => true,
            'query_var' => true,
            'capability_type' => 'post',
            'hierarchical' => true, //allow parent pages
            'show_in_nav_menus' => false,
            'menu_position' => 1000,
            'supports' => array(
              'title',
    		  'editor',
                  'page-attributes'
            )
          );
          register_post_type('Product',$args);
        }

    Thanks

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

    (@lynkei)

    Just marking this as resolved so noone wastes any time on answering it since in the meantime I took a different route.
    Thanks

Viewing 1 replies (of 1 total)
  • The topic ‘Use another custom post type as parent’ is closed to new replies.