2

I have created some custom fields in user profile from backend

templates/name-template/html/com_content/article/default.php

and use this code for load custom fields at joomla article

<?php 
$context = 'com_content.article';
$article = $this->item;

//use the field helper class to get the fields
JLoader::register('FieldsHelper', JPATH_ADMINISTRATOR . '/components/com_fields/helpers/fields.php');
$fields = FieldsHelper::getFields($context, $article, true);
// Added so as to access fields by their name

// GET CUSTOM FIELDS
foreach($fields as $field) {
    $fields[$field->name] = $field;
}
?>

and use this code for fetch

<?php echo ($fields['name-field']->value); ?>

i creat textarea fileds at user profile for write about me (author) enter image description here now I want to fetch users custom fields (author) in joomla article How can i do it ؟

1 Answer 1

2

Change context to com_users.user and the item to article author's user object. Since some articles may not have an author, this code should be wrapped in author check:

// Only run if article has an author.
if ($this->item->created_by)
{
    // Get author's custom fields.
    $fields = FieldsHelper::getFields('com_users.user', JFactory::getUser($this->item->created_by), true);

    // Display fields here.
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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