Get category parent also
-
Hi, the following function is returning only the category parent when the category child is designated in the post, but if you designate the category parent it ends up blank. How can I also acquire the parent category when the parent category is designated in the post?
function getCatButton($postID) { $postCat = get_the_category($postID); $postHTML = '<div class="button">'; if ($postCat[0]->parent != 0) { $cat = get_category($postCat[0]->parent); $postHTML = '<a href="'get_category_link($cat->cat_ID)'">'$cat->name'</a>'; } $postHTML = '</div>'; return $postHTML; }
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
- The topic ‘Get category parent also’ is closed to new replies.