Skip to content
Controls

Users

Users control lets you search and select WordPress users by role. Perfect for displaying team members, authors, or any user-related content.

Users Control

Control Settings

  • Filter by Role - Limit selection to specific user roles
  • Output Format - Choose between:
    • User ID - Returns user ID number
    • User Object - Returns full WP_User object
  • Multiple - Enable selection of multiple users

Usage Examples

Single User Selection

PHP with User ID
<?php
$user_id = (int) $attributes['control_name'];
$user = get_user_by('id', $user_id);
 
if ($user) : ?>
    <div class="user-card">
        <?php echo get_avatar($user->ID, 64); ?>
        <h3><?php echo esc_html($user->display_name); ?></h3>
        <p><?php echo esc_html($user->description); ?></p>
    </div>
<?php endif; ?>

Multiple Users

PHP with User IDs
<?php if ($attributes['control_name']) : ?>
    <div class="team-members">
        <?php foreach($attributes['control_name'] as $user_id) :
            $user = get_user_by('id', (int) $user_id);
            if ($user) : ?>
                <div class="member">
                    <?php echo get_avatar($user->ID, 96); ?>
                    <h4><?php echo esc_html($user->display_name); ?></h4>
                    <?php if ($user->user_url) : ?>
                        <a href="<?php echo esc_url($user->user_url); ?>">
                            Website
                        </a>
                    <?php endif; ?>
                </div>
            <?php endif;
        endforeach; ?>
    </div>
<?php endif; ?>

Using User Object

PHP with User Object
<?php if ($attributes['control_name']) : ?>
    <div class="author-box">
        <?php
        $user = $attributes['control_name'];
        echo get_avatar($user->ID, 120);
        ?>
        <h3><?php echo esc_html($user->display_name); ?></h3>
        <?php if ($user->description) : ?>
            <div class="bio">
                <?php echo wp_kses_post($user->description); ?>
            </div>
        <?php endif; ?>
    </div>
<?php endif; ?>

Handlebars Usage

Set Output Format to User Object when using Handlebars templates.

Single User
<div class="author-box">
  <h3>{{control_name.display_name}}</h3>
  <div class="bio">
    {{control_name.description}}
  </div>
</div>
Multiple Users
<div class="team-members">
  {{#each control_name}}
    <div class="member">
      <h4>{{this.display_name}}</h4>
      {{#if this.description}}
        <p>{{this.description}}</p>
      {{/if}}
    </div>
  {{/each}}
</div>

Post Meta

Post Meta
<?php
$user_id = get_lzb_meta('control_meta_name');
if ($user_id) {
    $user = get_user_by('id', (int) $user_id);
    if ($user) {
        echo '<div class="user-info">';
        echo get_avatar($user->ID, 64);
        echo '<h3>' . esc_html($user->display_name) . '</h3>';
        echo '</div>';
    }
}
?>

Use User Object format to access all user data without additional database queries.

Was this article helpful?