How to Create Hierarchical Custom Post Types in WordPress

css3 masonry layout

Large, collaboratively-created systems almost always contain pitfalls: misleading bits that don’t work the way they should. When someone thinks of these pitfall-prone systems, the English language, with all its/it’s inconsistencies, often comes to his/her/his or her/their/there/they’re mind.

WordPress is another example. One pitfall in WordPress is the process of creating a custom post type that is hierarchical: able to be organized into parent and child posts. (“Caramel Popcorn: Main Review” could be a parent Review post, for example, and “Popcorn: Taste In-Depth” and “Popcorn: A Deep Dive on Texture” could be child posts.)

The crux of the pitfall is that you need to register two properties to properly create a hierarchical post type. From the linked article:

To make a hierarchical custom post type, you have to have the ‘page-attributes‘ set in the ‘supports‘ array and the ‘hierarchical‘ flag set to true.

Please read the full linked article for details. It helped me out of a tight spot on a project where I needed to register CPTs by hand (rather than with a plugin like CPT UI). Much appreciated!


1 Response

Comments

  • Jake says:

    Thank you so much! Your advice helps. I’m using the CPT UI plugin. I’ve had the ‘hierarchical‘ flag set to true. But was still unable to create a child page under the specific custom post type.

    However it turned out that I did not turn on support for ‘page attributes’. Now I’m able to create child pages under the custom post type.

    Thanks!

Add a Comment

Your email address will not be published. Required fields are marked *