Skip Navigation

[Resolved] Proper way to setup structured taxonomies

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
#2631595

Tell us what you are trying to do?

I am trying to use Toolset to build an interface to manage and upload products that I will then pull utilizing the WP API. However, I need some guidance on the best way to structure the data. I'll number the questions as I go along.

In this case, the taxonomy would be something like the following:

Style -> Pattern -> Color

1) I need to be able to upload a thumbnail image for each style, pattern and color, so I don't think they can be configured as a dropdown select field. Is that correct?

However, I want to be able to restrict it so that you can only have 1 style, 1 pattern and 1 color per post type.

2) Is the only way to do this to elevate the taxonomy to a post type and build a relationship?

3) If I wanted to restrict it so only certain patterns were available for selection based on the style, etc, then I would have to definitely make them all post types and create those dependent relationships, is that correct?

If an example of the data as it is currently visualized is helpful, we have the customizer that will pull the data for use here: hidden link

Thank you!

#2631961

Hi,

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

For the structure that you're planning to achieve, the use of taxonomies alone won't work, because:

A). If you'd register 3 separate taxonomies for each level ( Style, Pattern, and Color ), they can't be connected/associated with each other.

B). And if you register a single taxonomy with hierarchal levels, you won't have the flexibility to select the terms for each level, in separate fields.

For this reason, I'll recommend using a combination of taxonomies and custom post types. Using 3 separate taxonomies for each level will help in the front-end filtering of the results. While attaching these taxonomies in a restricted and connected way, the custom post types with relationships will come in handy.

You can register 3 custom taxonomies for each level, for your 'Products' post type:
a). Style
b). Pattern
c). Color

But, you'll not be assigning these taxonomy terms through the regular taxonomy interface, because you need it in a restricted way.

Next, you can register these custom post types:
a). Style
b). Pattern
c). Color
d). Combination

As the names indicate, the 'Style', 'Pattern', and 'Color' post types will have posts with the same titles as the ones in their respective taxonomies.

The 'Combination' post type will have a one-to-many relationship with all other 3 post types so that each 'Combination' post can have exactly one 'Style', 'Pattern', and 'Color', post associated with it. This will allow you to establish which are the allowed combination for the 3 levels.

Lastly, there will be a one-to-many relationship between the 'Products' and 'Combination' posts. And when a combination post will be joined to a product, you can programmatically, assign relevant 'Style', 'Pattern', and 'Color' taxonomy terms to that product too.

I hope this makes sense and let me know if any point is not clear.

regards,
Waqar

#2632043

This is an interesting solution, thanks so much for such a comprehensive answer. When youy say programmatically assign, is this something Toolset has the capability of doing, or you mean custom code to do it using hooks?

Thanks so much!

#2632045

Sorry, one more question: how would you best keep the taxonomy and CPT objects in "sync?"

#2632483

Glad I could help.

> When youy say programmatically assign, is this something Toolset has the capability of doing, or you mean custom code to do it using hooks?

- I meant using a custom function linked to hook(s).

For example, Toolset relationships API offers the 'toolset_association_created' hook that is fired just after an association is created. And the 'toolset_before_association_delete' hook that is fired just before an association is removed.
https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/

> how would you best keep the taxonomy and CPT objects in "sync?"

- The website's admin will have to keep them in sync manually.

Alternatively, if you're comfortable with the PHP code, you can also attach some custom functions to the 'save_post' hook, that can detect changes to individual CPT posts:
https://developer.wordpress.org/reference/hooks/save_post/