I am attempting to get the latest article in a category that has a number of subcategories through the Articles ContentModel.
If I use $model->setState('filter.category_id', $this->category->id);
, it does not return anything due to the category in question not containing any articles; all of the articles are in subcategories.
How do I get all articles in the current category including children?
Code in question:
$model = JModelLegacy::getInstance('Articles', 'ContentModel', array('ignore_request' => true));
$model->getState();
// Set application parameters in model
$app = JFactory::getApplication();
$appParams = $app->getParams();
$model->setState('params', $appParams);
// Set the filters based on the module params
$model->setState('list.start', 0);
$model->setState('list.limit', 1);
$model->setState('filter.category_id', $this->category->id);
$model->setState('filter.published', 1);
// Permissions
$access = !JComponentHelper::getParams('com_content')->get('show_noauth');
$authorised = JAccess::getAuthorisedViewLevels(JFactory::getUser()->get('id'));
$model->setState('filter.access', $access);
// Featured Item
// Get article from featured set
// $model->setState('filter.featured', 'only');
// Ordering
$model->setState('list.ordering', 'a.publish_up');
$model->setState('list.direction', 'DESC');
$items = $model->getItems();