I have category which name is ’51m series’ (it has id 135). Why the expression is_category(51) is true on this category page? I think it should be false according to WordPress Codex. Is it a bug?
Wordpress 3.5.2
category.php
code:
<?php get_header(); ?>
<?php
if (is_category(array(36, 63, 64, 65, 67))) {
get_template_part('category', 'papers');
} elseif (is_category(array(5, 62, 61, 23, 17, 151))) {
get_template_part('category', 'icons');
} elseif (is_category(array(25, 50, 51, 52, 53, 54, 55, 56, 58, 71))) {
echo is_category(51);
get_template_part('category', 'gallery-machine');
} else {
get_template_part('category', 'gallery-frame');
}
?>
<?php get_footer(); ?>
51m series live You may see 1 (is_category(51)
) on the of the page.
My suspicion is that, for some reason, the
name
“51m series” orslug
51m-series
is (or both are) matchingis_category( 51 )
.The
is_category()
function uses the PHPin_array()
conditional to match against ID, slug, and name:The
in_array()
conditional appears to be returning true when51
is found in the name/slug51m series
/51m-series
. While both the name and slug conditional checks should be case-sensitive, none of the checks are strict. So the integer51
is possibly being evaluated as a string against$cat_obj->name
, and matching51m Series
(or against$cat_obj->slug
, and matching51m-series
)Possible solutions:
This may also be a case where core needs to perform a
strict
check inin_array()
, to differentiate between an ID integer and a name/slug string.