Not sure the message was sent as it didn't appear in my sent box, so I re-post it here :
Hi Colin, this is the code I use :
function getJCFields($srcId, $fieldId=null, $dbfields=null, $context=null)
{
if( is_null($context) )
$context = 'com_jdownloads.download';
if( is_array($srcId) || is_object($srcId) ) {
JLoader::register('FieldsHelper', JPATH_ADMINISTRATOR.'/components/com_fields/helpers/fields.php');
$jfields = FieldsHelper::getFields($context, $srcId, true);
}
else
if( is_int($srcId) )
{
if( is_null($dbfields) )
$dbfields = 'id,label,value,item_id';
$db = JFactory::getDbo();
$db->setQuery('
SELECT '.$dbfields.'
FROM #__fields
LEFT JOIN #__fields_values ON #__fields.id = #__fields_values.field_id
WHERE context = "'.$context.'"
AND #__fields_values.item_id = '.$srcId.'
AND #__fields.state = 1
');
$jfields = $db->loadObjectList();
}
$fieldval=[];
foreach($jfields as $val)
{
$fieldval[$val->id] = (object)['label'=>$val->label,'value'=>$val->value];
}
$fval = $fieldval;
if( !is_null($fieldId) ) {
$fval = $fieldval[$fieldId];
}
return $fval;
}
And to call the function:
$srcid = ['id'=>578]; // ID (578) of the download that we want to get the customs fields
echo getJCFields($srcid, 1)->label; // label of the custom field number 1
echo getJCFields($srcid, 1)->value; // value of the custom field number 1
Thank you
Erik