Created
June 4, 2013 22:27
-
-
Save thadallender/5710177 to your computer and use it in GitHub Desktop.
Filter post_class to return terms from a custom taxonomy in WordPress
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function custom_taxonomy_post_class( $classes, $class, $ID ) { | |
$taxonomy = 'pcategory'; | |
$terms = get_the_terms( (int) $ID, $taxonomy ); | |
if( !empty( $terms ) ) { | |
foreach( (array) $terms as $order => $term ) { | |
if( !in_array( $term->slug, $classes ) ) { | |
$classes[] = $term->slug; | |
} | |
} | |
} | |
return $classes; | |
} | |
add_filter( 'post_class', 'custom_taxonomy_post_class', 10, 3 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment