3

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:

  1. 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)
  2. 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 :)

6
  • You can extend the depth of a hierarchical taxonomy any time. Why do you think you can't?
    – fuxia
    Apr 7, 2013 at 14:03
  • @toscho If I add stuff at the beginning of the hierarchy each existing level changes meaning. Think of it this way: with the 1st approach, I don't have a list of taxon ranks, with the 2nd approach I do (but there are too many disadvantages).
    – Christian
    Apr 7, 2013 at 14:07
  • @toscho, as I understand it, each level would have to represent a specific type of relationship-- Family, Genus and Species-- which means that the levels are locked. The nesting level is how you determine what is a Family, what is a Genus, and what is a Species. You can't insert anything else-- SubFamily, for example, between Family and Genus without throwing off that relationship. What the OP needs, I think, is a kind of a key/value taxonomy, not just a value taxonomy. I am not quite sure how to pull that off.
    – s_ha_dum
    Apr 7, 2013 at 14:09
  • That made me think, what if I go with the first approach but instead have two custom taxonomies: plant_classification and plant_class_ranks? @s_ha_dum is correct, that's my problem.
    – Christian
    Apr 7, 2013 at 14:09
  • I was also wondering if a two taxonomies might be the way to do it. I think that might be the only way using WordPress Core functionality, without writing your own classification system.
    – s_ha_dum
    Apr 7, 2013 at 14:11

3 Answers 3

1

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:

Admin needs to select all applicable classification parts when associating to a plant (eg; a family, a genus and a species)

Rhamnaceae
- Ziziphus
-- Ziziphus Jujuba

If you check Ziziphus Jujuba then that plant post is automatically in the Ziziphus group and also automatically in the Rhamnaceae group.

Programatically, I lose the ability to find family from genus

You can always chase a term "up the tree" by checking a term's parent. get_term() returns an object with the property parent which is 0 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.

// get all the terms for a particular post
$plant_terms = wp_get_post_terms( get_the_ID(), 'plant_class' );

//assuming there are terms to loop through
if( $plant_terms && !is_wp_error($plant_terms)) {

    //lets pop off the first term (shouldn't there be only one?)
    $plant_term = array_shift($plant_terms);

    //check that term's parent ID and follow it upwards
    //when you get to a top-level term $plant_term->parent = 0
    //so the loop will break
    while ( $plant_term->parent > 0 ){
        $plant_term = get_term( $plant_term->parent );
    }

    //this should echo the family name
    echo $plant_term->name;

}

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

  1. Limiting the inputs to only the 3rd "species" level. My Radio Buttons for Taxonomies plugin can help you limit to only a singular input, but wouldn't force it to be the "species" level. (FWIW- it needs an update for a bug fix for adding terms, but I'm working on it). Though maybe you could fork my plugin and use a little jQuery to limit the input.
2
  • You slightly misunderstood my problem, please see the comments under my question.
    – Christian
    Apr 7, 2013 at 14:33
  • Well as you said "I'm finding it a bit hard to explain my problem". The comments don't make it a lot clearer for me unfortunately. To me, the biggest problem seems to be that you need to restrict the inputs to always respect the Family/Genus/Species structure. I think this should be doable by replacing the default taxonomy metabox with something custom. Sorry I couldn't help more. Good luck! Apr 7, 2013 at 14:49
1

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 in hierarchy.

0
0

Since I already have a custom taxonomy for plant details, this is what my structure will look like:

 Plant Details (custom taxonomy)
   |- Class Ranks                      classification ranks
   | |- Family               <-.
   | |- Genus                <-|-.
   | '- Species              <-|-|-.
   |- Plant Classes            | | |   plant classification
   | '- Rhamnaceae           --' | |
   |   '- Ziziphus           ----' |
   |     '- Ziziphus Jujuba  ------'
   '- Plant Types                      other plant details...
     |- Cactus
     |- Herb
     '- Tree

This is my proposed answer thanks to input from @s_ha_dum

1
  • This is the answer though..
    – Christian
    Apr 7, 2013 at 14:58

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.