Skip to content
Block 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 (users_role) - limit the search to specific user roles. Empty by default, which searches every role
  • Output Format (users_output_format) - User ID by default:
    • User ID - Returns user ID number
    • User Object - Hands the block a full WP_User object
  • Multiple (multiple) - off by default. On, the control accepts several users and stores an array

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>';
    }
}
?>

The block stores user IDs either way. User Object runs the get_users() call for you as the block renders, so your template reaches display_name without making the query itself.

Was this article helpful?

Copyright © 2026 Lazy Blocks.