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!


Add a Comment

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