Repeating user fields can have more than one value. Types let you create repeating user fields.

Repeating user fields are useful when you need to include several instances of the same field. For example, people might have several phone numbers or addresses.

Then, you can display these repeating fields using Views or Types API functions.

Creating Repeating User Fields

When creating a user field you can define it as repeating by selecting the Allow multiple-instances of this field option in the Single or repeating field section.

Allow multiple-instances of field
Allow multiple-instances of field

When you select Allow multiple-instances of this field, the content edit screen will include the Add new button. Click this button to add more values to your field.

Here is how it looks like:

Entering data to repeating field
Entering data to repeating field

Displaying Repeating Fields

Types API will load all values for repeating fields and display them one after the other. You can specify the separator that goes between items.

Let’s consider the following code:

Specifying the separator
[types usermeta="phone-number" separator=", " user_is_author="true"][/types]

It will output something like this:

+1-202-555-0155, +1-202-555-0101, +1-202-555-0203, +1-202-555-0123

The following code:

Unordered list
<li>[types usermeta="phone-number" separator="</li><li>" user_is_author="true"][/types]</li>

… will output an unordered list:

  • +1-202-555-0155
  • +1-202-555-0101
  • +1-202-555-0203
  • +1-202-555-0123

While this code:

Ordered list
<li>[types usermeta="phone-number" separator="</li><li>" user_is_author="true"][/types]</li>

… will output an ordered list:

  1. +1-202-555-0155
  2. +1-202-555-0101
  3. +1-202-555-0203
  4. +1-202-555-0123

Index: Displaying a single value for a repeating field

The index parameter will return a single value from a repeating field. This uses zero-based numbering, so the first element has an index=”0″, the third has an index=”2″, and so on.

The above example would return the second value for the phone-number repeating field.

You can change the order of the repeating field values using drag-and-drop directly from the post edit screen.

Displaying Repeating Fields using PHP

If you are using only the Types plugin, you can display repeating fields in your templates using custom PHP code. Learn more about this topic on the page about displaying repeating fields using PHP.