I’m trying to implement plant classification as a custom taxonomy for a custom post type.
For now, plant classification should be on three levels: Family
, Genus
, Species
.
As I see it, there are two possible ways:
-
Using taxonomy level as an indicator of taxonomy type, ex:
plant_class (custom taxonomy) '-- Rhamnaceae (level 1 = family) '-- Ziziphus (level 2 = genus) '-- Ziziphus Jujuba (level 3 = species)
Advantages:
- Correct structure; I’d be able to find the family name of a given genus.
- Administrator just selects a species to classify a plant.
Disadvantages:
- Cannot be extended later on (eg; to introduce sub-species)
- The per-level aspect looks too “magical” to me (unintuitive / confusing to beginners)
-
Putting each name under the classification type itself, ex:
plant_class (custom taxonomy) |-- Family (group of families) | '-- Rhamnaceae |-- Genus (group of geni) | '-- Ziziphus '-- Species (group of species) '-- Ziziphus Jujuba
Advantages:
- Easily extensible (to add sub-species or even order at a higher level)
Disadvantages
- Admin needs to select all applicable classification parts when associating to a plant (eg; a family, genus and species)
- Programatically, I lose the ability to find family from genus (broken hierarchy)
Another (and even wilder) idea I’ve had is to create several taxonomies (plant_family
, plant_genus
, plant_species
) and somehow form a relation between each taxonomy type so that a family can be associated to several geni. I’ve no idea how this would work.
Wondering why there’s no code? Well, it’s relatively easy to create custom taxonomies, and what I’m missing is purely a system design issue.
Ref: Biological Classification | WordPress Taxonomy Reference | Ziziphus 🙂
Why not use a hierarchical taxonomy? I can’t think of a better use for hierarchy than what you are describing. As far as your perceived disadvantages:
If you check
Ziziphus Jujuba
then that plant post is automatically in theZiziphus
group and also automatically in theRhamnaceae
group.You can always chase a term “up the tree” by checking a term’s parent.
get_term()
returns an object with the propertyparent
which is0
when it is a top-level term and ID number of its parent when it is not.Say for example you are on a plant post that is classified in the
Ziziphus Jujuba
group.I think you could make that
while
loop more complex, maybe with a counter, to know when you are on which level.The potential pitfall that I see is
Create the hierarchy as a hierarchical custom post type
hierarchy
, and create the taxonomy structure as you need it.Then use the Posts 2 Posts plugin to map each
plant
to one or more items inhierarchy
.Since I already have a custom taxonomy for plant details, this is what my structure will look like:
This is my proposed answer thanks to input from @s_ha_dum