I have an ID of an article, and want to know it's parent category details. To get category details by it's ID i've read an API that i need code like this:
$categories = JModelLegacy::getInstance('Categories', 'ContentModel', array('ignore_request' => true));
$categories->setState('filter.published', 1);
$categories->setState('filter.access', $access);
$items = $categories->getItems();
But this gives me (via j-dump) a list of objects not filtered at all. What setState filter i must apply to: 1) only one result 2) filtered by category ID (visible in admin, not asset ID)= XX
And, if possible - how to get article's parent category?
I get a specific category like this:
$options = array();
$categories = JCategories::getInstance('Content', $options);
$category = $categories->get($article->catid);
From there you can use
$parent = $category->getParent();
To get the parent category of the selected $category.
Update: To get the catid of the article, use this MySQL query:
SELECT `catid` FROM `#__content` WHERE `id` = $article_id
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With