Check if current term is a child of another term

Question

I’m attempting to make an archive template that will apply only to subcategories of a particular term. My structure looks something like this:

  • Events (main taxonomy)
    • Tradeshow
      • Show subcat 1
      • Show subcat 2
    • Other taxonomies

I want Show subcat 1 and Show subcat 2 (and any other subcategories) to all get the same archive template. This is one of my attempts at it, which is definitely not working. Here’s the code from my functions.php.

    add_filter( 'template_include', 'kd_event_subcategory_archive' );

    function kd_event_subcategory_archive( $template ) {
        $term = get_queried_object()->term_id;
        if ( $term->parent == 'tradeshow' ) {
            $event_subcat = locate_template( 'taxonomy-tradeshow-subcategory.php' );

            return $event_subcat;
        }

        return $template;
    }

I can’t seem to figure out how to properly check if a term is the child of my tradeshow term.

0
, , , KreigD 7 months 0 Answers 77 views 0

Leave an answer