Conditional Content and Custom Fields

Search
Other Bug Reports questions
Forum

Conditional Content and Custom Fields

W's Avatar W
Can I apply conditions to a custom field?
Example: (Using Joomla 3)
1a. I've added a custom field for users, which is a list (User > Fields)
1b. Created a new field for users (marital status) with three options (single, divorced, married)
2. I want users that are of a status (ex: married) to see content conditionalized with married, and users that are not married to have that content hidden.

How do I apply conditions based on this? I've have conditionalization working, but want to know how to use it with custom fields added to users and/or content.
Peter van Westen's Avatar Peter van Westen ADMIN
This is not possible with the Joomla 3 version of Conditional Content.
At is possible on Joomla 4.
Please post a rating at the Joomla! Extensions Directory
W's Avatar W
I see, thanks. Where is the documentation for using this feature with J!4?
W's Avatar W
Hoping there is documentation on applying conditions to extra fields for users and extra fields in content...
W's Avatar W
If I want to filter content by data at the profile level, how do I setup filters to display content that is applied at the profile level? (I don't see any filter extensions that enable this).
Peter van Westen's Avatar Peter van Westen ADMIN
Ah, sorry... missed the part about this being about user fields, not article fields.

There is no ready-to-use condition for that.
But you can do this via the PHP condition rule. Something like this:
JLoader::register('FieldsHelper', JPATH_ADMINISTRATOR . '/components/com_fields/helpers/fields.php');
$fields = FieldsHelper::getFields('com_users.user', $user, true);

$marital_status = '';

foreach ($fields as $field)
{
    if($field->name == 'marital_status') {
        $marital_status = $field->value;
        break;
    }
}

return $marital_status == 'single';
Please post a rating at the Joomla! Extensions Directory
You can only post on this forum if you log in