Forums

Check if category has parents? (1 post)

  1. cMadman
    Member
    Posted 5 years ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Topic