I am getting one category id in code but it can be the id of either category or subcategory. And by the following code i am able to fetch the parent category chain.

$Jcategories = JCategories::getInstance('Content');
$cat = $Jcategories->get($category->id);
print_r($cat->getParent()); //gives me all the parent details including the main category but it is under [_parent:protected] => JCategoryNode Object( ) so not able to access this.

Otherwise, I will have to write multiple queries to find parent of parent id. Now, I want to know the main parent id of this category. Example the chain is -


  • Sports
    • Running
    • basketball
  • Casual
    • Sneakers

here, if the $category->id is of running(subcategory) then I want it's main category i.e. SHOES . If the $category->id is of Casual(category) then also, I should get the main category SHOES.

  • Are you are using an e-commerce plugin, it would be helpful to know which one if so, and also what you are trying to achieve?
    – Dtorr1981
    Jul 13 '17 at 1:47

Your Answer

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

Browse other questions tagged or ask your own question.