Check if category has parents?
-
I’ve just solved this issue but I’m interested to know whether I’ve done it the easiest / most efficient way (and I wanted to get it in the search engine so other users could resolve the issue faster). I couldn’t see a function dedicated to it so after browsing some of the WordPress Core code I tried this, which works fine for me.
I use this to pull in the category object:
$parent = &get_category($catID);
Once that’s done, checking the value of
$parent->category_parent
can be used to test for parents.As I understand it, anything greater than 0 would mean the category has parents.
- The topic ‘Check if category has parents?’ is closed to new replies.