From fdb0fcbafe07949f88b5c4cbd095480c73d71185 Mon Sep 17 00:00:00 2001 From: Peter Westwood Date: Wed, 27 Feb 2008 18:25:25 +0000 Subject: [PATCH] A better in_category which supports category names that are all numbers. git-svn-id: https://develop.svn.wordpress.org/trunk@7064 602fd350-edb4-49c9-b593-d223f7449a82 --- wp-includes/category-template.php | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/wp-includes/category-template.php b/wp-includes/category-template.php index ba47b677f6..ca1299d436 100644 --- a/wp-includes/category-template.php +++ b/wp-includes/category-template.php @@ -167,12 +167,24 @@ function get_the_category_list($separator = '', $parents='', $post_id = false) { return apply_filters('the_category', $thelist, $separator, $parents); } +/* + * in_category() - Checks whether the current post is within a particular category + * + * This function checks to see if the post is within the supplied category. The categoy + * can be specified by number or name and will be checked as a name first to allow for categories with numeric names. + * Note: Prior to v2.5 of WordPress category names where not supported. + * + * @since 1.2.0 + * + * @param int|string $category + * @return bool true if the post is in the supplied category +*/ function in_category( $category ) { // Check if the current post is in the given category global $post; - if ( !is_numeric($category) ) { - $category = get_cat_ID($category); - } + $cat_ID = get_cat_ID($category); + if (0 != $cat_ID) + $category = $cat_ID; $categories = get_object_term_cache($post->ID, 'category'); if ( false === $categories )