Get template part based on custom taxonomy term

To loop through all the slugs of a term list, simply call get_the_terms() and pull only the slugs:

$slugs = wp_list_pluck( get_the_terms( get_the_ID(), 'prodcat' ), 'slug' );

Then you need to check if you got any results:

if ( ! empty( $slugs ) )

The problem I then see arising is that you got a bunch of slugs in return (unless you restricted the admin meta box to allowing only a single term).

You’d then have to decide on some custom criteria which nav menu you want to have and pull that from the list of $slugs:

// Decide which slug fits and then determine the key:
$key = 0;
get_template_part( 'nav', $slugs[ $key ] );

Leave a Comment