<?php

defined('_JEXEC') or die;

 

use Joomla\CMS\Layout\LayoutHelper;

 

// Load the FieldsHelper

 

JLoader::register('FieldsHelper', JPATH_ADMINISTRATOR . '/components/com_fields/helpers/fields.php');

$item->jcfields = FieldsHelper::getFields('com_content.article', $item, true);
$fields = [];
foreach($item->jcfields as $jcfield)
{
$item->jcFields[$jcfield->name] = $jcfield;
}

?>

 

 

<?php echo $item->jcFields['cfname']->value; ?>

 

cfname is the name of your custom field