2

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
  • 1
    Unfortunately this is an opinion-oriented question and the variables of each use case will dictate the best data structure. Does it make sense to have a parent movie that contains children that are also movies? Probably not, maybe so. The same is true for eyeglasses. Of the two example CPTs you listed, classifying the type of movie with a category or custom taxonomy makes more sense, to me. But that could be considered my opinion. – jdm2112 Jul 31 '18 at 15:44
2

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.