Get all Child Category IDs

  • Posts: 303
  • Thank you received: 18
4 years 10 months ago #318489

-- HikaShop version -- : 4.2.3
-- Joomla version -- : 3.9.16

How would i get all child category ids from a parent category id? Trying to implement something inside a view file that only displays if within a category or any of the child categories.

Thanks,
Holden

Please Log in or Create an account to join the conversation.

  • Posts: 83409
  • Thank you received: 13502
  • MODERATOR
4 years 10 months ago #318503

Hi,

You can do like that:

$class = hikashop_get('class.category');
$categories = $class->getChildren(XXX, true, array(), '', 0, 500);
where XXX is the id of the parent category.

Please Log in or Create an account to join the conversation.

  • Posts: 303
  • Thank you received: 18
4 years 10 months ago #318604

Thanks Nicolas. I'm unable to pull out the category ids only. Looks like $categories is a array of objects?

I really just need to dump all "category_id" to one array.

Please Log in or Create an account to join the conversation.

  • Posts: 83409
  • Thank you received: 13502
  • MODERATOR
4 years 10 months ago #318608

Yes, $categories will contain all the data of the categories.
But then you can easily extract the category_id of each category with a loop:

$ids = array();
foreach($categories as $category) {
 $ids[] = $category->category_id;
}

Please Log in or Create an account to join the conversation.

Time to create page: 0.042 seconds
Powered by Kunena Forum