0

In my module i get the articles via this way:

$model = JModelLegacy::getInstance('Articles', 'ContentModel', array('ignore_request' => true));
$model->setState('params', JFactory::getApplication()->getParams());
$model->setState('filter.category_id', 22);

This gets all the articles from a specific category. But now I have the issue that the Fields from the com_fields component are not retrieved via this method. I probably have to do that myself. Does anyone know how to add the fields?

Something like

$model->addFields();
1

Normally fields are added by the Fields plugin. You can trigger onContentPrepare event to run this and other content plugins:

JFactory::getApplication()->triggerEvent('onContentPrepare', ['com_content.article', &$article, &$article->params]);

Fields will be available via jcfields property on the article object.

Another option is to manually use FieldsHelper class:

JLoader::register('FieldsHelper', JPATH_ADMINISTRATOR . '/components/com_fields/helpers/fields.php');
$fields = FieldsHelper::getFields('com_content.article', $article);
1
  • Works perfectly, thank you
    – Huub S
    May 6 at 8:41

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.