6 thoughts on “Utility Taxonomies

  1. Great article, and much needed too. I believe this approach was adopted by WooCommerce for their starred products.

    I think it may help developers is they had the possibility to display these boolean taxonomies as a predef radio button to users. Maybe add a parameter when registering a taxonomy?

    These small UI changes can make a big difference in changing mindsets of both developers and users.

    Cheers.

  2. This is a great tip! I see Jetpack is using a private term “featured” (a post tag) for it’s featured posts. And querying posts by taxonomy has great performance.

  3. Hi Tom,

    Thanks for the article, I know this is an older thread but I’m curious as to your opinion on the following:

    Using a utility taxonomy as a sort of boolean for tax queries, what is the most efficient method for querying?

    The taxonomy I’m testing only has one term, named ‘yes’.

    Objective: get all the posts which have this term (or any within the utility taxonomy, as this is the only one).

    Methods tested:

    1)
    $tax_query = array(
    array(
    ‘taxonomy’ => ‘utility-taxonomy’,
    ‘terms’ => ‘yes’,
    ),
    );

    2)
    $tax_query = array(
    array(
    ‘taxonomy’ => ‘utility-taxonomy’,
    ‘operator’ => ‘EXISTS’,
    ),
    );

    3)
    $term_id = get_term_by( ‘name’, ‘yes’, ‘utility-taxonomy’ )->term_id;
    $tax_query = array(
    array(
    ‘taxonomy’ => ‘utility-taxonomy’,
    ‘terms’ => $term_id,
    ),
    );

    4) Something else?

    I’m not seeing a huge difference in performance between these options, so I’m curious as to what the best method would be.

    • They’re essentially doing different versions of the same thing, I would not expect any performance difference.

      There may be performance differences in more extreme situations, e.g. 500 million posts, but I do not expect them to be meaningful in difference.

      I would note however, that using an entire taxonomy for just the word “yes” is not a very good use of a utility taxonomy. The term doesn’t describe what it does, and if you ever needed another boolean value you would have to register another utility taxonomy.

      That’s why my example is “show-on-homepage”, not “yes” or “show”.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.