0

We are building a resorts site and we're facing a huge taxonomy problem.

On one side, we have administrative locations such as country>>region>>department and "natural" locations, such as mountain-range>>sub-mountain range. This can be sorted out just by arranging two different taxonomies, like admin-locations and natural-locations, for example. This sounds easy, but not so much when you realize that some resorts share two or more places. There's even one resort that belongs to three European countries at the same time!

But we're also dealing with other kinds of locations, such as national parks (which can cover two or more regions or departments, for example), regional parks, natural parks, tourist regions and sub-regions, even valleys, lakes or items that could only fit in an "other" kind of special label.

So the only solution we can think of is to build more taxonomies and add some term metas to sort of organize all this mess by linking terms of different taxonomies. Say, for example, you want to list which resorts there are in some national park that covers two regions and at the same time is in two different tourist areas, and is also part of a bigger several-resort area with five other resorts.

We have some dozens of such cases, literally. So we want the user to see, for example, a menu with some different options drop-down that tell them, well, their options.

Today my question is not about building such a menu. It is about how to organise that taxonomies mess. We're aware that there is a performance and scale problem when querying when you have post and term metas, so it is a bit of a complex problem for us. We've thought that we could "connect" terms of different taxonomies with term meta, but we're not completely sure of how exactly and if it would be then easily queryable and sortable.

Our problem becomes apparent with an example:

Say the user is viewing France>>some region>>some department. We should be able, on one side, to offer him/her to see the natural locations available in that area (remember, a mountain range can cover several departments, regions and even countries, even a sub-mountain range can do that. The same goes for parks or tourist areas). On the other hand, they must be aware of the national, regional and natural parks in that zone, as well as the tourist regions, smaller tourist regions inside those, etc etc.

All these items must be terms in taxonomies so the user can see the list of resorts available in them.

How would you go about these different ways to organise locations? Remember, the main problem is one kind of location can cover part of other kind of location, or can mix with other types of locations in different combinations.

Thanks in advance.

**** UPDATE for clarity ****

The site is about Resorts, so that is a CPT.

Administrative locations, natural locations, valleys, parks and tourist regions are all locations, so taxonomies. I'm guessing each kind of location is a different hierarchical taxonomy.

The main problem here is like in this example, which is a real one:

User is viewing a list of resorts that are in country-1>>region-1>>department-1.

Let's say that, in this department, there is a regional-park-1. So one obvious requirement is to show the user this optional location in the menu or options dropdown. If the user clicks, he/she will see a list of resorts in regional-park-1. That's easy.

The complexity comes with this: let's say that regional-park-1 also covers another department, with the department-2 taxonomy term. So, when the user is in regional-park-1, we need him/her to see department-1 and department-2 in our menu/options. But since regional-park-1 can only belong to one of the two departments, we have a problem. One solution could be for parks to be another taxonomy and make its terms to be related with terms from the admin-locations taxonomy, in this case department-1 and department-2.

This can become worse easily: there's a tourist-area-1 that covers regional-park-1 and a regional-park-2 next to it. So, while our user still is in regional-park-1, we need to show him/her (dinamically) that there's also tourist-area-1 available with its own list of Resorts, that may be different from the lists of the other Taxonomy Terms mentioned.

This example's scheme would be:

Tax admin-locations:    Parks:            Tourist-areas
country-1
    region-1
        department-1____regional-park-1____tourist-area-1
        department-2____regional-park-1
        another dept____regional-park-2____tourist-area-1

This can get more complex with valleys that can belong to even three different countries, Resorts (cpt) that belong to more than one country, tourist areas inside greater tourist areas, regional parks that belong to national parks and at the same time extend beyond the border to become regional park of another country but now this part is not in a national park, etc.

We must find a way to relate taxonomies so, when the user is on any taxonomy term viewing the list of Resorts for that location, show them dinamically what other related locations are available.

So, again, the question is how would you organise things to accomplish this.

Thanks.

0

Set your system up like this:

  • locations - CPT
  • administrative - hierarchical taxonomy
  • natural - hierarchical taxonomy
  • type - non-hierarchical taxonomy

In the administrative taxonomy, you would create your tree: countries on the first level, regions second, departments and so on. Then, you would assign your locations to the smallest administrative denominations among your taxonomies - like the departments in your example. Next, in the taxonomy page you list all posts in that taxonomy and its children (that is actually the default).

The same approach goes for the natural taxonomy. Go as deep as you need and attach your posts to the "leafs" of your taxonomy tree.

As for the types of locations, you would not have separate taxonomy pages, but use them in the administrative and natural taxonomies to filter your view to that exact type of location: hotel, park and so on.

UPDATE:

Taxonomies are used for classification, and I don't think linking the leaves from different taxonomy trees would be a good idea. AFAIK, WP does not allow that either.

But you have no obligation to limit yourself to only one CPT. The way I see your situation, you have your resorts CPT, but you should also add CPTs for the parks and tourist areas. This way, you would have 3 CPTs in total, all sharing 2 custom taxonomies: admin and natural.

After that, you'll need to link some of these CPTs together. I can think of 3 possible solutions to do that:

  1. Use their geographical position: add an ACF Google Map field for each post, save lat and lng in separate meta fields (ACF stores the address, lat and lng in a serialized field so you cannot query them), then use $wpdb->get_results to query the DB directly and get your CPTs by distance (see Distance between Latitude and Longitude Coordinates in SQL or MySQL calculate distance between two latitude/longitude coordinates).
  2. Connect your posts using Posts 2 Posts: that used to work great, and, AFAIK, it still does today, but the author of the plugin stopped supporting it 2 years ago. From what I researched a couple of months before, there is no better alternative for linking posts, either free or paid.
  3. A workaround simulating #2: use ACF Relationship fields + ACF Post-2-Post. This plugin only works with ACF v.5, so you need to use either the PRO version of ACF, or download the free variant of v.5.x from their site, as on the WP plugin repository they still have v.4.x.

Depending on your exact needs and capabilities, you could use any of the above methods, and possibly even combine #1 with #2 or #3.

  • 1: So you're saying, for example, query for cpt's that belong to country-1>>region-1>>department-1 that are also in a specific A-regional-park tax term in 'type' tax, right? (if I understand you correctly). Problem: Let's say that A-regional-park covers also another department, department-2. And there's also an A-tourist-area that covers this park and another B-regional-park next to A-regional-park. When the user is in A-regional-park, we need to tell them that A-tourist-area is available (because is related to this park, and has a different list of cpt's) – Karls Sep 3 '17 at 16:38
  • 2: and also that other department-2 which this park belongs to, as well. There's a myriad of possible combinations, so I think taxonomy terms must be related somehow, presumably with term meta. This way, when user is in A-regional-park, they can automatically see an option to go to A-touristic-area and the other department-2. Since A-tourist-area is just another term in the same non-hierarchical 'type' taxonomy (just like many others), there's no way to offer it unless you've make a relation to A-tourist-region 'type' taxonomy term. Same goes to the department-2. – Karls Sep 3 '17 at 16:38
  • 3: Since originally we queried for country-1>>region-1>>department-1 with 'type' A-regional-park, there's no way to dinamically make department-2 appear as an option. Only if we establish a relation between department-2 ('admin' taxonomy term) and A-regional-park ('type' taxonomy term), which at the same time has an establiahed relation with department-1 ('admin' taxonomy term). I know, this is very convoluted ;) – Karls Sep 3 '17 at 16:38
  • There is no relation between the administrative and type - a regional park could be defined anywhere, not necessarily in one department. But a location (CPT) that belongs to several administrative areas could display the locations in those areas too - wp_get_post_terms() + WP_Query. So, A-regional-park would be a location (CPT) belonging to dept1 and dept2 (admin taxonomies) and to regional park ( type taxonomy). Then B-regional-park, A-tourist-area and so on would be other locations. – Mihai Papuc Sep 3 '17 at 21:26
  • 1
    Yes, those might work. I'll give them a try. For now, I'm trying the ACF Pro Taxonomy field, which allows to link taxonomy terms via term meta. I'm being careful with ACF's scalability, performance and database queries problems. If I can, I'll try to keep parks and tourist areas as taxonomies, easier to manage for lists, menus and keeping consistency. ACF's relationship fields could also work if I go for several cpt's. I like P2P very much (Scribu is a great developer), but it's not mantained. Let me try and if any of this works I'll accept your answer. Thanks. – Karls Sep 4 '17 at 23:11

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.