Alt. for in_cat_hierarchy()?
-
I use WP as a CMS for my site, and in doing so, I have a lot of posts in different multiple child categories. To help correctly identify and display the posts, I added the following code that was placed up here on the support forum by a member ‘ringmaster’, which sort of broke down after I upgrade to 2.1.
I kind of figured out what really went wrong, but I don’t know how to fix it. $categories needs to be an array for foreach loop to work, but somehow it’s just not becoming one. I’ve confirmed that $category_cache is an array, since I managed to get it to show me its keys and values.
Please help me out, my website can’t work (and look) well without this code.
function in_cat_hierarchy($cat, $postid = '') {
global $category_cache, $cache_categories, $post;
if ('' == $postid) $postid = $post->ID;
$incats = array();
update_post_category_cache($postid);
$categories = $category_cache[$postid];
foreach ($categories as $category) {
$incats[$category->cat_ID] = true;
$incats[$category->category_nicename] = true;
$parent = $category->category_parent;
while($parent != 0) {
$incats[$parent] = true; $incats[$cache_categories[$parent]->category_nicename] = true;
$parent = $cache_categories[$parent]->category_parent;
}
}
return !empty($incats[$cat]);
}
- The topic ‘Alt. for in_cat_hierarchy()?’ is closed to new replies.