From 461ac5808d9b9c10f775fa3b86aa3aa16872a8a6 Mon Sep 17 00:00:00 2001 From: ryan Date: Wed, 22 Oct 2008 21:31:55 +0000 Subject: [PATCH] Fix in_category() when checking non-cached categories. fixes #7181 git-svn-id: http://svn.automattic.com/wordpress/trunk@9289 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/category-template.php | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/wp-includes/category-template.php b/wp-includes/category-template.php index 4ce4ccd0bf..7033519d87 100644 --- a/wp-includes/category-template.php +++ b/wp-includes/category-template.php @@ -288,12 +288,19 @@ function in_category( $category ) { } $categories = get_object_term_cache( $post->ID, 'category' ); - if ( false === $categories ) - $categories = wp_get_object_terms( $post->ID, 'category' ); - if ( array_key_exists( $category, $categories ) ) + if ( false !== $categories ) { + if ( array_key_exists( $category, $categories ) ) + return true; + else + return false; + } + + $categories = wp_get_object_terms( $post->ID, 'category', 'fields=ids' ); + if ( is_array($categories) && in_array($category, $categories) ) return true; else return false; + } /**