Skip to content

User Field in WordPress

Key Takeaways

  • Nexter Extension 4.9.0 adds a User field in Nexter → Content Fields that stores a reference to a WordPress user, so the name, avatar, and contact details stay correct when that user updates their profile.
  • Filter by Role and Select Multiple shape the picker: Filter by Role limits users to specific roles, and Select Multiple lets editors choose more than one value when a post needs multiple users.
  • get_userdata() must resolve the stored ID before rendering, because deleted users no longer return data and multisite networks keep user meta shared across sites while field groups stay per-site.
Table of Contents

A user field lets an editor pick one or more registered users — a listing agent, a recipe author, an account manager — without retyping their name on every post.

What It Does

The field stores a reference to a WordPress user. Because it is a reference, the name, avatar and contact details stay correct when that user updates their profile.

Before You Start

  • Nexter Extension is installed and active.
  • Content Fields is enabled under Nexter → Content Fields.
  • You have a field group, or are about to create one.

Add a User Field

  1. Go to Nexter → Content Fields and open the Group Fields tab.
  1. Open a field group, or create a new one.
  1. Click Add Field.
A field group open with the Add Field button
  1. Set Field Label to Listing agent. The Field Name fills in automatically and is what you use in code.
  1. Set Field Type to User.
The Field Type dropdown listing the available field types
  1. Use Filter by Role to limit the picker to the roles that make sense.
The User field settings in the Content Fields builder
  1. Turn on Select Multiple if a post can have more than one.
  1. Click Update.
The User field as it appears on the post editing screen

Field Settings

Every field is configured across four tabs. These are the settings this field type offers, read from the field group builder in Nexter Extension 4.9.0.

General

SettingOptionsWhat it does
Filter by RoleNo help text in the UI.
Return FormatNo help text in the UI.
Select MultipleLet editors pick more than one value.

Validation

SettingOptionsWhat it does
RequiredNo help text in the UI.

Presentation

SettingOptionsWhat it does
InstructionsNo help text in the UI.
Wrapper AttributesNo help text in the UI.

Conditional Logic

SettingOptionsWhat it does
Conditional LogicNo help text in the UI.

When to Use It

  • The agent handling a property.
  • A reviewer or approver on an article.
  • The owner of a directory entry.

Display the Value

With an ID returned, look the user up when you render:

<?php
$user_id = nxt_field_value( 'agent' );
if ( $user_id ) {
    $user = get_userdata( $user_id );
    if ( $user ) {
        echo esc_html( $user->display_name );
        echo get_avatar( $user_id, 64 );
    }
}

Limitations

  • If that user is deleted, the stored ID no longer resolves. Check the lookup before rendering.
  • On a multisite network, user meta is shared across sites while field groups are per-site — see the multisite notes before relying on user fields across a network.

Troubleshooting

The picker does not list the person I want

Filter by Role is excluding them. Either widen the roles, or give that user a role you allow.

Nothing renders

get_userdata() returns false for a deleted user. Guard the lookup as in the example above.

Related Docs

Share your Thoughts

Still in Doubt? Let’s Assist You

Have Feedback or Questions?

Join our WordPress Community on Facebook!