0

I'm hardly an expert on the matter but from reading around this Q&A site i have the following notion that one Post Type cannot be the Parent of another Post Type.

What i can't seem to answer is why?

If i have a post type of Neighborhoods because they tend to have a lot of specific information relevant to them wouldn't that make sense to be a Post type?

If i have a post type of Places because there is a lot of information relevant to a place (building, memorial, eatery, etc) wouldn't that make sense to be a Post type?

Then wouldn't it make sense that places are within neighborhoods and therefore have a Parent/Child relationship where Neighborhood is the parent of Places?

Why is it not possible then to structure them that way then in a simple manner, or am i missing something here?

Finally why are the same types of Custom Post Types able to be parents of another (ex: Neighborhood1 can be the parent of Neighborhood2 and vice versa) how does that make any sense?

Why would there be a need to make another post of the same post type a child of itself?

When what seems more logical is to have one post type be the parent of another.

My entire understanding, from what i've read and from what i've been working on, is that one would create a Custom Post Type when a specific kind of repeatable data type will have to be created (neighborhoods, teachers, cars, computers, etc) why then would it ever make sense to have those be hierarchical within themselves?

Thanks

0

Because a Post Type is stored in the database under the wp_posts table column post_type. The reason a post type can't have a parent post_type is because there is no database taxonomy mapping like there is for a post categories.

http://codex.wordpress.org/Post_Types

  • thank you for pointing this out to me that makes a lot of sense and while i read the Post Types page on the codex i completely missed this point. – MARS Oct 2 '13 at 13:10
0

To understand hierachical post type you have to think to the first hierachical post type in WordPress: pages. Before WordPress 3 there was no custom post types at all, there was only post (not hierachical) and pages (hierachical).

Building a company site you can have a page 'About Us'. Then you can have some pages 'Our Location', 'Our Staff' and so on. these pages can be children of 'About Us' page.

Doing so you can do 2 things:

  • Using function like wp_list_pages these pages are shown in nested lists, in this way everything appear more organized
  • The url for a child page became http://www.example.com/about-us/our-location/ giving to site a tree organization that is a good for seo.

Note that custom menu in WordPress appear with WP 3.0 and befor this version only way to display a list of pages is using functions like wp_list_pages so first point was more important in the past than now, but second point is still important in these days.

In short general scope of hierachical post types is to put in parent post some informations and in child posts details that can be organized in a tree-like scheme.

The reason why a post type cannot be a parent for another post type is mainly storical and regard the way the parent-child relationship is handled in WordPress.

To relate one post type to another, there are some ways.

The first, is create a taxonomy shared between post types, in this way you can create a relation of the type many-to-many.

The second is create a custom field in a post to link the other post type. E.g. in your case in a post of Places type, you can create a custom field called 'neighborhood_id' and there put the id of the 'Neighborhood' post you want to use as parent. This will create a relation one-to-many.

Another, commonly used, way is use the Posts To Posts plugin (aka P2P) that allow you to create relation between post types, using one-to-one, one-to-many and many-to-many relation type.

It's a well known plugin, developed by scribu one of WP core developers (and user of this site).

  • This is a great answer and truly changed my approach i will post a follow up after playing around with your recommendations to figure which angle will work best in this situation. Thank you. – MARS Oct 2 '13 at 13:08
  • It seems to me that i should have all of my neighborhoods and places within the same post type and put all the custom fields that they would need as a whole within this custom post type and then call on different fields from their respective templates. Second instead of me creating taxonomies for neighborhoods and places alone i should be creating a taxonomy of Washington DC because really my entire site focuses on that city alone yet all neighborhoods and places are within that city. So it appears i wasn't looking at this from the highest hierarchical viewpoint possible. – MARS Oct 2 '13 at 13:12

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.