Created
January 5, 2015 22:26
-
-
Save bjonesy/abf779ff6ec2710ec28e to your computer and use it in GitHub Desktop.
Filter out the uncategorized category from an array
This file contains hidden or 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
<?php | |
/** | |
* Filter out the uncategorized category from an array | |
*/ | |
function theme_slug_remove_uncategorized( $categories ) { | |
return array_filter( $categories, function( $c ) { | |
return $c->name != 'Uncategorized'; | |
} ); | |
} | |
// Example usage | |
$terms = get_the_terms( $post->ID, 'category' ); | |
$terms = theme_slug_remove_uncategorized( $terms ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment