Hierarchical Custom Post Types in WordPress Chris Coyier

Publish date: 2024-09-30

July 19, 2022

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

register_post_type( 'docs', array( '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, <strong>'hierarchical' => true, </strong> 'supports' => array( 'title', 'editor', 'thumbnail', 'excerpt', <strong>'page-attributes'</strong> ) ) );Code language: PHP (php)

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.

🤘

ncG1vNJzZmibmKe2tK%2FOsqCeql6jsrV7kWlpa2dgbHxyhY6hoJ6qkaewqbXCmqNmm6WowbC5jKmmrKxdqcaxsdJmoKdlp6S%2FpbzRnqqsZw%3D%3D