Hierarchical Custom Post Types in WordPress

You need to set both of these things to make it work correctly:

register_post_type( 'docs',
    'labels'        => array(
      'name'          => __( 'Documentation' ),
      'singular_name' => __( 'Documentation Page' ),
      'add_new'       => __( 'Add Documentation Page' ),
      'add_new_item'  => __( 'Add New Documentation Page' ),
      'edit_item'     => __( 'Edit Documentation Page' ),
    'public'       => true,
    'has_archive'  => true,
    'rewrite'      => array( 'slug' => 'docs' ),
    'show_in_rest' => true,
    'hierarchical' => true,
    'supports'     => array( 'title', 'editor', 'thumbnail', 'excerpt', 'page-attributes' )

Now when you are on the Create/Edit screen for the new Post Type, you’ll see the Page Attributes area that allows you to select the Parent you’d like.

One response to “Hierarchical Custom Post Types in WordPress”

  1. N.A. Ferrell says:

    I followed a guide to create custom post types with a plugin on my site, but I did not know about the possibility of making the hierarchical. May have to make use of this – thank you for the guide.

Leave a Reply

Your email address will not be published.