0

How can I get parent category ID in single page template, outside of loop?

$category = get_the_category(); 
echo $category[0]->term_id;

The code isn't working outside loop correctly.

2
  • This should work on single posts, see this answer. What happens on your site? Are there other queries on that page?
    – fuxia
    Commented Jun 5, 2013 at 5:32
  • I need parent category ID, it returns just category ID. Anyway, I got the solution and posed as answer.
    – IFightCode
    Commented Jun 5, 2013 at 8:38

1 Answer 1

2

I'm solved, by using:

$category[0]->parent

Thanks anyway.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.