Access User Custom Fields Topic is solved

For Joomla! 3.x Coding related discussions, you could also use: http://groups.google.com/group/joomla-dev-general

Moderators: ooffick, General Support Moderators

Forum rules
Locked
DrDave
Joomla! Apprentice
Joomla! Apprentice
Posts: 25
Joined: Thu Mar 24, 2011 3:01 pm

Access User Custom Fields

Post by DrDave » Fri Jan 14, 2022 6:16 am

I'm using Joomla 3.10.4

I have two user custom fields, called season-joined and membership-status. I'm look for the php code that would allow me to do this:

If season-joined = "2021-2022" and membership-status = "Active" return true, otherwise, return false.

Any help is appreciated.

User avatar
Per Yngve Berg
Joomla! Master
Joomla! Master
Posts: 30819
Joined: Mon Oct 27, 2008 9:27 pm
Location: Romerike, Norway

Re: Access User Custom Fields

Post by Per Yngve Berg » Fri Jan 14, 2022 8:34 am

Mod. Note: Relocated topic from J4 to J3 forum.

User avatar
toivo
Joomla! Master
Joomla! Master
Posts: 17361
Joined: Thu Feb 15, 2007 5:48 am
Location: Sydney, Australia

Re: Access User Custom Fields

Post by toivo » Mon Jan 17, 2022 5:07 am

Here is one way how to access user custom fields in an override of the profile view of the Users component in the Protostar template. Create the override in Template Manager.

Code: Select all

// insert after line 34 of templates/protostar/html/com_users/profile/default_custom.php
$seasonJoined		= '';
$membershipStatus	= '';
foreach ($tmp as $customField)
{
	switch ($customField->name)
	{
		case 'season-joined':
			$seasonJoined		= $customField->value;
			break;
		case 'membership-status':
			$membershipStatus	= $customField->value;
			break;
		default:
			echo '<br>Unknown custom field: ' . $customField->name;
	}
}
echo '<br>Season joined ' . $seasonJoined . ' Membership status ' . $membershipStatus;

The same code works also in a profile override in Joomla 4.x:

Code: Select all

// insert after line 29 of templates/cassiopeia/html/com_users/profile/default_custom.php
$seasonJoined		= '';
$membershipStatus	= '';
foreach ($tmp as $customField)
{
	switch ($customField->name)
	{
		case 'season-joined':
			$seasonJoined		= $customField->value;
			break;
		case 'membership-status':
			$membershipStatus	= $customField->value;
			break;
		default:
			echo '<br>Unknown custom field: ' . $customField->name;
	}
}
echo '<br>Season joined ' . $seasonJoined . ' Membership status ' . $membershipStatus;
Toivo Talikka, Global Moderator

DrDave
Joomla! Apprentice
Joomla! Apprentice
Posts: 25
Joined: Thu Mar 24, 2011 3:01 pm

Re: Access User Custom Fields

Post by DrDave » Sat Feb 19, 2022 9:45 pm

Sorry for the late reply...this is helpful. Thank you.


Locked

Return to “Joomla! 3.x Coding”