Page as a child of a Custom Post Type

I have a custom post type called “Professions”, it contains different professions and info about them. To show them I simply use a content-profession.php -file.

The thing is that I need subpages (childs) to those professions that contains info like salary, terms, where to find jobs, etc. They cannot be of the same type as the CPT Professions since that post type have a very specific layout. Is there any way to get a normal page as a child of a custom post type?

This was previously discussed here:

Page as child in custom post type slug?

but with the solution of rewriting URLs which feels like a very “hacky” solution to the problem.

2 Answers
2

When you register the post type you can set hierarchical to true.

hierarchical
(boolean) (optional)

Whether the post type is hierarchical (e.g. page). Allows Parent to be specified. The ‘supports’ parameter should contain ‘page-attributes’ to show the parent select box on the editor page.

Default: false

Note: this parameter was planned for Pages. Be careful, when choosing it for your custom post type – if you are planning to have many entries (say – over 100), you will run into memory issue. With this parameter set to true WordPress will fetch all entries of that particular post type, together with all meta data, on each administration page load for your post type.

Then make sure the supports array includes page-attributes to show the parent menu.

eg:

// Register post type
register_post_type('your-post-type' , array(
    'labels' => $labels,
    'hierarchical' => true,
    'supports' => array( 'title', 'editor', 'page-attributes' )
) );

More info in the codex

Leave a Comment