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.

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

I'm solved, by using:

$category[0]->parent

Thanks anyway.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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