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.
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.
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.
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:
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.
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.
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.
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.
This is exactly where Toolset can help you. With Toolset, you can display custom user fields anywhere on your site, without PHP coding. See an example on how to build front-end forms in order to create user accounts.