Retrieving user custom fields in Joomla 3.7

Joomla 3.7 brings many exciting new features, but the most notable one is the ability to use custom fields in order to display additional attributes on an article, a user or a contact. In this tutorial we are discussing the use of usercustomfields modification function for retrieving the custom fields associated with a user entry.

The usercustomfields expects the following arguments separated by colon character:

  • The id of the column where the user id value appears
  • The id of the header row where the custom field label/title will appear
  • The preferred language for the fields, which can be a specific language tag (e.g. en-GB) or one of the following values:
    • current: the current Joomla language selected by the user/visitor
    • all: basically, it's like saying ignore the language field.
    • *: all languages - unlike the all option, this will include only fields whose language is set to "all".
  • The list of custom fields and where they should appear. Here is a sample list format: 2=3|6,4=9,7=12|31
    In this example:
    • 2 -> The column id where the custom field(2) #3 or #6 will appear, depending on the current language.
    • 4 -> The column id where the custom field #9 will appear.
    • 7 -> The column id where the custom field(2) #12 or #31 will appear, depending on the current language.

Let's look at the specific example.

  • 1: the column id where the user id values appear (1st column).
  • 1: the header row where the custom field labels/titles should appear (1st row)
  • all: get all custom fields in the list, regardless of the language settings.
  • 2=3: in the 2nd column add the custom field #3
  • When you add this rule it's recommended that you set the priority parameter to any value larger than 0, so this rule is executed first.
  • The user id column is required for the modification function to work. Nevertheless, if you don't to display this information later on, you can remove this column with another rule of lower priority once the usercustomfields has been executed.
  • Make sure that the column id of the inserted custom fields is within the available column range of the input table.

If you haven't done it before here is how to add a new rule to an existing ruleset. If you want to learn more about modification functions click here.

Click here to download the usercustomfields modification function. Once you have download the zip file, unzip it locally and copy the usercustomfields.php file to {joomla root directory}/templates/tabulizer/modify folder.