Hierarchical or Non-hierarchical Custom Post Type in Real World Example

Well the simplest answer is a Non-hierarchical Custom Post Type is like regular posts and a Hierarchical Post Type is like a page but this still confusing for me.

I can understand easily the difference between Hierarchical and Non-Hierarchical Taxonomies which can make a Tag or a Category but this usage is not vary clear in case of creating a CPT.

So in a real world example if I want to create a Custom Post Type for Movie and one for Eyeglasses should I make them Non-hierarchical or Hierarchical? I mean i need to know the logic of that

1 Answer
1

Do you need to be able to have/assign a parent post?

If yes, then use hierarchical, if not then don’t.

Hierarchical post types allow you to do one way post to post relations of the type 1:many, which is useful sometimes. E.g. pages, documentation, etc.

Also keep in mind that a post can have a parent, even if it’s in a non-hierarchical post type, as post parent is a table column and a universal attribute. Post parents don’t have to be of the same post type either, but you would need to implement the UI for that.

Keep in mind though, that sometimes a taxonomy is a more appropriate method of applying hierarchy/structure.

In the grand scheme of things, setting something as non-hierarchical is a very safe bet, since non-hierarchical post types can be made hierarchical at a later date without data loss. The need for a hierarchical CPT is not so common, and the decision itself isn’t as important as CPT vs Taxonomy, and isn’t as important as people might think

Leave a Comment