The Types plugin allows you to easily add custom user fields. You can use them to create different user profiles for different types of users. This page guides you on how to display these fields in your PHP templates. To accomplish this without PHP coding, you can use the complete Toolset suite instead.

Adding custom fields to user profiles

You can create a group of custom user fields on the Toolset Custom Fields page and click on Add New. After that click on User Fields. Next step is to name your group and add the fields you need.

Creating/editing a group of custom user fields
Creating/editing a group of custom user fields

You can create separate user profile groups for different types of users. For example, Subscribers could have a completely different set of custom user fields compared to those of Authors.

Use the Where to display this group box to select the user types for which the group will be used.

Box for selecting the user roles for which the group of fields will be used
Box for selecting the user roles for which the group of fields will be used

Displaying custom user fields

You can display custom user fields inside any main PHP template in your theme, such as the author archives or single posts.

To output the user fields created with Types, use the following function:

echo types_render_usermeta("custom-field-slug-name", array("argument1″=>"value1″,"argument2″=>"value2″,"argument2″=>"value2"));

For example, you might output a custom field about your staff’s role using the following line:

echo types_render_usermeta("staff-role");

Custom user fields displayed on the author’s archive page
Custom user fields displayed on the author’s archive page

User fields have the exact same syntax and arguments as custom post fields. Detailed list of all Types Fields with the corresponding arguments and values can be found on the Types Fields API documentation page.

Creating a custom user archive

WordPress uses the author.php template for displaying the user archive page. If your theme does not feature this template, you can create one based on the archive.php template.

To view a fully documented example of the PHP template used on this documentation page, go to the examples folder in the Types plugin and search for the author.php file.

Example folder as found under the Types plugins’ directory
Example folder as found under the Types plugins’ directory

The example file provides you with an example code for three important things:

  • Displaying standard WordPress user fields using the get_the_author_meta function.
  • Displaying Types custom user fields using the types_render_usermeta function.
  • Creating a custom query for our author/user to display posts belonging to the “Post” and “Book” post types.

The following is an example of an entire author.php template described above.

Wrapping up

Creating custom user fields and profiles with Types is simple and affords powerful possibilities when displayed in the site’s PHP templates. However, this often proves to be difficult for non-programmers and beginners. Additionally, it is a time-consuming process for most people.

Customized user profile page using multiple custom user fields
Customized user profile page using multiple custom user fields

This is exactly where Toolset can help you. With Toolset, you can display custom user fields anywhere on your site, without PHP coding. Visit our training courses and lessons to learn how to build front-end forms in order to create user accounts.