Frequently Asked Questions

Here's a list of the most frequently asked questions about the Advanced Custom Fields extension

How to load an article's custom fields with PHP?

To get the article's custom fields programmatically with PHP, use the code below:

$article_id = 5; // Enter your article ID here

$model = JModelLegacy::getInstance('Article', 'ContentModel');
$article = $model->getItem($article_id);

JLoader::register('FieldsHelper', JPATH_ADMINISTRATOR . '/components/com_fields/helpers/fields.php');
$fields = FieldsHelper::getFields('com_content.article', $article, true);

The $fields variables is an Array of Objects, and you can loop through it like in the example below:

foreach ($fields as $key => $field)
{
    echo $field->title . ' = ' . $field->rawvalue;
}
Last updated on Mar 4th 2025 10:03