Hello, I'm tring to get my articles custom fields to show on the category page.
I managed to do it, but I'm having a weird issue.
I created 2 custom fields.
When I print custom fields array on my page, I get them twice.
I call the fields like :
JLoader::register('FieldsHelper', JPATH_ADMINISTRATOR . '/components/com_fields/helpers/fields.php');
$jcFields = FieldsHelper::getFields('com_content.article', $item, true);
$array = json_decode(json_encode($jcFields), true);
print_r($array);
Did I call them wrong ?
Is this the way it should work ?
I can call each diffrent value with :
echo $array[0]['rawvalue'];
echo $array[2]['rawvalue'];
But it's a bit confusing..
In the print_r result we can see that custom field with same ID appears twice.
Array
(
[0] => Array
(
[id] => 1
[title] => Détails
[name] => details
[checked_out] => 0
[checked_out_time] => 0000-00-00 00:00:00
[note] =>
[state] => 1
[access] => 1
[created_time] => 2018-03-15 13:13:40
[created_user_id] => 42
[ordering] => 0
[language] => *
[fieldparams] => Array
(
[buttons] =>
[width] =>
[height] =>
[filter] => safehtml
)
[params] => Array
(
[hint] =>
[render_class] =>
[class] =>
[showlabel] => 1
[show_on] =>
[display] => 3
[display_readonly] => 2
)
[type] => editor
[default_value] =>
[context] => com_content.article
[group_id] => 1
[label] => Détails
[description] =>
[required] => 0
[language_title] =>
[language_image] =>
[editor] =>
[access_level] => Public
[author_name] => Super User
[group_title] => Infos supplémentaires
[group_access] => 1
[group_state] => 1
[value] => <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
[rawvalue] => <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
)
[1] => Array
(
[id] => 2
[title] => Galerie
[name] => galerie
[checked_out] => 0
[checked_out_time] => 0000-00-00 00:00:00
[note] =>
[state] => 1
[access] => 1
[created_time] => 2018-03-15 13:17:50
[created_user_id] => 42
[ordering] => 0
[language] => *
[fieldparams] => Array
(
[directory] =>
[multiple] =>
[image_class] =>
)
[params] => Array
(
[hint] =>
[render_class] =>
[class] =>
[showlabel] => 1
[show_on] =>
[display] => 2
)
[type] => imagelist
[default_value] =>
[context] => com_content.article
[group_id] => 1
[label] => Galerie
[description] =>
[required] => 0
[language_title] =>
[language_image] =>
[editor] =>
[access_level] => Public
[author_name] => Super User
[group_title] => Infos supplémentaires
[group_access] => 1
[group_state] => 1
[value] =>
[rawvalue] => -1
)
)
Array
(
[0] => Array
(
[id] => 1
[title] => Détails
[name] => details
[checked_out] => 0
[checked_out_time] => 0000-00-00 00:00:00
[note] =>
[state] => 1
[access] => 1
[created_time] => 2018-03-15 13:13:40
[created_user_id] => 42
[ordering] => 0
[language] => *
[fieldparams] => Array
(
[buttons] =>
[width] =>
[height] =>
[filter] => safehtml
)
[params] => Array
(
[hint] =>
[render_class] =>
[class] =>
[showlabel] => 1
[show_on] =>
[display] => 3
[display_readonly] => 2
)
[type] => editor
[default_value] =>
[context] => com_content.article
[group_id] => 1
[label] => Détails
[description] =>
[required] => 0
[language_title] =>
[language_image] =>
[editor] =>
[access_level] => Public
[author_name] => Super User
[group_title] => Infos supplémentaires
[group_access] => 1
[group_state] => 1
[value] => <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
[rawvalue] => <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
)
[1] => Array
(
[id] => 1
[title] => Détails
[name] => details
[checked_out] => 0
[checked_out_time] => 0000-00-00 00:00:00
[note] =>
[state] => 1
[access] => 1
[created_time] => 2018-03-15 13:13:40
[created_user_id] => 42
[ordering] => 0
[language] => *
[fieldparams] => Array
(
[buttons] =>
[width] =>
[height] =>
[filter] => safehtml
)
[params] => Array
(
[hint] =>
[render_class] =>
[class] =>
[showlabel] => 1
[show_on] =>
[display] => 3
[display_readonly] => 2
)
[type] => editor
[default_value] =>
[context] => com_content.article
[group_id] => 1
[label] => Détails
[description] =>
[required] => 0
[language_title] =>
[language_image] =>
[editor] =>
[access_level] => Public
[author_name] => Super User
[group_title] => Infos supplémentaires
[group_access] => 1
[group_state] => 1
[value] => <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
[rawvalue] => <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
)
[2] => Array
(
[id] => 2
[title] => Galerie
[name] => galerie
[checked_out] => 0
[checked_out_time] => 0000-00-00 00:00:00
[note] =>
[state] => 1
[access] => 1
[created_time] => 2018-03-15 13:17:50
[created_user_id] => 42
[ordering] => 0
[language] => *
[fieldparams] => Array
(
[directory] =>
[multiple] =>
[image_class] =>
)
[params] => Array
(
[hint] =>
[render_class] =>
[class] =>
[showlabel] => 1
[show_on] =>
[display] => 2
)
[type] => imagelist
[default_value] =>
[context] => com_content.article
[group_id] => 1
[label] => Galerie
[description] =>
[required] => 0
[language_title] =>
[language_image] =>
[editor] =>
[access_level] => Public
[author_name] => Super User
[group_title] => Infos supplémentaires
[group_access] => 1
[group_state] => 1
[value] =>
[rawvalue] => -1
)
[3] => Array
(
[id] => 2
[title] => Galerie
[name] => galerie
[checked_out] => 0
[checked_out_time] => 0000-00-00 00:00:00
[note] =>
[state] => 1
[access] => 1
[created_time] => 2018-03-15 13:17:50
[created_user_id] => 42
[ordering] => 0
[language] => *
[fieldparams] => Array
(
[directory] =>
[multiple] =>
[image_class] =>
)
[params] => Array
(
[hint] =>
[render_class] =>
[class] =>
[showlabel] => 1
[show_on] =>
[display] => 2
)
[type] => imagelist
[default_value] =>
[context] => com_content.article
[group_id] => 1
[label] => Galerie
[description] =>
[required] => 0
[language_title] =>
[language_image] =>
[editor] =>
[access_level] => Public
[author_name] => Super User
[group_title] => Infos supplémentaires
[group_access] => 1
[group_state] => 1
[value] =>
[rawvalue] => -1
)
)
Joomla! 3.8.7
PHP 7.0.29
MySQL 5.6.40
I get the same issue with :
JLoader::register('FieldsHelper', JPATH_ADMINISTRATOR . '/components/com_fields/helpers/fields.php');
$jcFields = FieldsHelper::getFields('com_content.article', $item, true);
print_r($jcFields);
json_decode and json_encode are not causing this.
Title |
|
||||||
Status | New | ⇒ | Information Required |
Hi @ggppdk,
Sorry for the late answer, I just noticed it.
I tried your code, but result is the same.
What I'm trying here is to get the value of specific custom fields in articles category page.
Anyway I managed to get the result I needed with:
JLoader::register('FieldsHelper', JPATH_ADMINISTRATOR . '/components/com_fields/helpers/fields.php');
$jcFields = FieldsHelper::getFields('com_content.article', $item, true);
$myCustomFields = array();
foreach($jcFields as $field) {
$myCustomFields[$field->name] = $field->value;
}
$GLOBALS['myCustomFields'] = $myCustomFields;
print_r($GLOBALS['myCustomFields']);
Here I get also same result with:
$jcFields = FieldsHelper::getFields('com_content.article', $item, true);
And:
$jcFields = !empty($item->jcfields)
? $item->jcfields
: FieldsHelper::getFields('com_content.article', $item, true);
OK, thank you for the info.
Best regards
@ShapesGraphicStudio can you please close this Issue if info by @ggppdk was helping?
Status | Information Required | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2018-06-14 13:57:44 |
Closed_By | ⇒ | ShapesGraphicStudio |
Instead of
$jcFields = FieldsHelper::getFields('com_content.article', $item, true);
Try