Hey guys on my wordpress blog I am trying to compare the following if ($category[0]->cat_name == "television" ) in wordpress the $category[] is the array of categories a post has, and cat-name i just the actual name of that category. If I echo $category[0]->cat_name it is television but I can't get this to flag as true for the if statement, something is wrong and it keeps doing the ELSE part. Anyone know what is wrong here? thank you alot for any help Travis
$category[0]->cat_name = $cat; if ($cat == "television"){ echo"worked"; }else{ echo"didn't work"; } Try this. If it still doesn't work try not using exactly equal to just one qual sign because some spaces may be messing it up.
try this if (strtolower($category[0]->cat_name)=="television") { // your expression if works } else { // your expression if it doesn't } PHP:
php might have treated $category[0]->cat_name as an object, rather than a string. You can try typecast it. if ((string) $category[0]->cat_name == "television" ) { // } PHP: