WordPress.org

Ready to get started?Download WordPress

Forums

Query Multiple Taxonomies
Writing Multiple Taxonomies in Body Class? (2 posts)

  1. gumlor
    Member
    Posted 3 years ago #

    Is it possible to list multiple taxonomies, both the keys and the values, in the body tag class? Something like, for http://www.my-site.com/?genre=jazz&artist=bb-king :

    <body class="... tax_genre_jazz tax_artist_bb-king">

    I've tried the following code, but it ONLY works when there is a single taxonomy and it only show the key but not the value:

    add_filter('body_class','mysite_body_class');
    function mysite_body_class( $classes ) {
    	if( is_tax() ) {
    		global $taxonomy;
    		if( !in_array( $taxonomy, $classes ) )
    			$classes[] = "taxonomy " . "taxonomy-".$taxonomy;
    		}
    	return $classes;
    }

    Thanks a million for your help!

  2. scribu
    Member
    Plugin Author

    Posted 3 years ago #

    You can use qmt_get_terms() instead of the $taxonomy global.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic