Mirroring Taxonomy Terms as Sub Terms to Another Taxonomy in WordPress

First off, don’t do this (also, say that post title 10 times fast; r/titlegore).
It’s better to not have to write logic into an app so that two things can see the same data from different parts of the db. It should be stored only in one spot and referenced from there. However, within a framework, when you’re using plugins whose code you’re not familiar with, sometimes it’s the way of least resistance. At first anyways, I suppose it depends on how complicated it is.

Now that’s out of the way, let me get to my weak excuses.

I needed to set up multi-taxonomy sort ordering. I need the sorting to be drag and drop, and it needs to automatically create the UI based on what terms are in the taxonomy. I haven’t been able to find a plugin which does all of this. I use one which allows for single taxonomy sorting and it hit’s all the other buttons. But I don’t know the plugin code well and I don’t currently have the time to do so.

I found another which can do multi-taxonomy sorting but it’s UI could be confusing for my clients and you need to manually set up the sorting UI’s. So, each time they add or remove a term they’d need to remove/add a set of options for that term. Not gonna happen.

My roundabout choice was to use the first mentioned plugin and mirror one of the taxonomies as sub categories to another.

Practically speaking in my context I have a custom post type, Projects (each project represents a spot/video), a Talent taxonomy (list of people’s names) and a Spot Type taxonomy (subjects for videos the”Talent” edit). The taxonomies are registered with the custom post type.

I’m mirroring the Spot Types terms to the Talent taxonomy as child categories/terms. I’m doing this because I don’t want to have the clients need to individually add the sub categories for each talent taxonomy term; there will be a lot. The code I wrote will take in two taxonomies; the taxonomy to mirror and the taxonomy to mirror to. On plugin activation all the terms in the TAXONOMY_TO_MIRROR_NAME will be added as sub terms to each of the TAXONOMY_TO_MIRROR_TO_NAME top level terms (aka, term->parent === 0). They will subsequently be created, updated, and deleted when any of the TAXONOMY_TO_MIRROR_NAME terms are (all together now) created, updated, and deleted.

The plugin still needs a proper going through, but if you need something like this here is a place to test and start.

There is a repository.

 

 

References
A helpful plugin for a confusing UI: Categories in Hierarchical Order | WordPress.org

https://github.com/ronalfy/reorder-by-term
Function Reference/add option « WordPress Codex
get_option() | Function | WordPress Developer Resources
Function Reference/update option « WordPress CodexWP_Term_Query::__construct() | Method | WordPress Developer Resources
Categories in Hierarchical Order | WordPress.org