Skip Navigation

[Resolved] When to use Types Relationships vs. CPT parent/child hierarchy?

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)

Author
Posts
#2650189

Hello, I am setting up a new site and am trying to decide the best way to structure the CPTs and relationships.

I have Rental Properties and each Rental Property has Units. A Unit is basically an apartment type, such as Swanky Penthouse, Tiny Studio, Industrial Loft. (For ease of discussion, let's say that in each Rental Property no two units are alike.) Units are unique to each building (don't need to compare Swanky Penthouses across the different properties, for example).

I think Rental Properties and Units both need to be posts of some kind, and not a taxonomy, because there is a lot of information and custom fields that are needed for each. Where I am undecided is whether I should use Types Relationships or a Custom Post Type with parent/child hierarchy.

It's a one-to-many relationship -- each Rental Property has multiple Units, but each Unit only belongs to one Rental Property. So the traditional CPT parent/child hierarchy would work in that regard. But, Rental Properties have a different set of custom fields than Units. (I do realize I can conditionally show/hide field groups based on whether it's a Rental Property or a Unit.)

My question is, are there advantages or disadvantages to using one of these over the other?
1. Native WP relationship: Create a Custom Post Type: Rentals. When you create a Rental post, you choose in the custom fields whether it's a Rental Property or a Unit. The remaining custom field groups conditionally show the proper set of fields for that option. Rental Properties are parent posts, and each Unit post is a child of one of the Rental Property posts, using native WP post hieararchy
2. Types Relationship: Create two Custom Post Types: Rental Properties and Units. Each have their own set of custom fields. Relationship between the two CPTs are created using Types Relationship.

I've built sites using both methods and I cannot remember why in each case the decision was made to go in one of these directions or the other. There will be associated taxonomies for both Rental Properties and Units, and searching/filtering across the two. Can someone please explain why one structure would be chosen over the other, or what limitations exist that should make me choose one method over the other? Many thanks for any insight you can give.

Note: While I realize each setup is unique, and I am asking you for advice on this specific setup, I am most interested in more general strategy and limitations. For example, I found your documentation of Custom Fields vs. Taxonomies very helpful because it included information such as "you can order posts by custom field values but not by taxonomies" and "displaying posts by taxonomy is faster than displaying them by custom fields." Thank you!

#2650331

Hi,

Thank you for contacting us and I'd be happy to assist.

I appreciate how clearly you were able to share your project's requirements and your existing understanding of what to expect going with each of these approaches.

The main advantage that I see of using the 'Native WP hierarchical relationship' (where 'property' and 'units' are part of the same CPT) is the URL/permalink structure.

For properties, you'll have the URL:
{yourwebsite.com}/property/{property-slug}

And for the child unit, you'll have the URL:
{yourwebsite.com}/property/{property-slug}/{unit-slug}

The disadvantage of this approach is that you won't be able to create a search form where 'properties' and 'units' can be used as independent search fields.
( because they'll be part of the same CPT )

For most cases and general usage, this is the structure that I'll recommend:

Custom Post Types:
- Properties
- Units

Post Relationships:
- Properties -> Units
( a one-to-many relationship where one property can have many units )

Custom Taxonomy:
- Unit Type
( a taxonomy attached to the 'Units' post type, which will have terms like Swanky Penthouse, Tiny Studio, Industrial Loft, etc )

I recommend this based on what makes the most sense in terms of data storage as well as what operations can be performed on that data later.

regards,
Waqar

#2650475

Thanks for your help. I hadn't thought about the permalink structure. And good point about not being able to search properties and units separately because they'd be the same CPT. I think I have what I need for now but I will open a new ticket if I have additional questions. Thank you!