Ask any question about WordPress here... and get an instant response.
Post this Question & Answer:
How can I create a custom post type with hierarchical capabilities in WordPress?
Asked on Feb 15, 2026
Answer
Creating a custom post type with hierarchical capabilities in WordPress allows you to organize content similar to pages, where you can have parent and child relationships. This is particularly useful for structuring content that requires a hierarchy.
<!-- BEGIN COPY / PASTE -->
function create_custom_post_type() {
$args = array(
'label' => 'Books',
'public' => true,
'hierarchical' => true,
'supports' => array('title', 'editor', 'thumbnail', 'page-attributes'),
'has_archive' => true,
'rewrite' => array('slug' => 'books'),
);
register_post_type('book', $args);
}
add_action('init', 'create_custom_post_type');
<!-- END COPY / PASTE -->Additional Comment:
- The 'hierarchical' parameter is set to true, enabling parent-child relationships similar to pages.
- Use the 'supports' array to specify features like 'title', 'editor', and 'page-attributes' for ordering.
- Ensure the 'has_archive' parameter is true if you want an archive page for the custom post type.
- Modify the 'rewrite' slug to customize the URL structure for your custom post type.
Recommended Links:
