Controls
Users
Users control creates a dynamic set of users to search and select from and used to store a user ID value for the block. See examples below to use this control.
Control Settings
- Filter by Role – filters the selectable results via one or more user roles. When left empty, all users will be shown
- Output Format – specifies the returned value format. Choose from
User ID
(integer) orUser Object
(WP_User) - Multiple – select a single or multiple users
Usage
PHP
$selected_user = get_user_by('id', (int) $attributes['control_name']);
?>
<p>
<?php echo $selected_user->display_name; ?>
</p>
PHP + Multiple
<?php foreach( $attributes['control_name'] as $user_id ): ?>
<?php
$selected_user = get_user_by('id', (int) $user_id);
?>
<p>
<?php echo $selected_user->display_name; ?>
</p>
<?php endforeach; ?>
PHP with Output Format as User Object
<p>
<?php echo $attributes['control_name']->display_name; ?>
</p>
<p>
<?php echo $attributes['control_name']->user_email; ?>
</p>
To use Users control with Handlebars, you should set the
Output Format
option to User Object
, because we don't have a specific Handlebars helper to work with WordPress users.Handlebars
<p>
{{control_name.display_name}}
</p>
Handlebars + Multiple
{{#each control_name}}
<p>
{{this.display_name}}
</p>
{{/each}}
Post Meta
<p>
<?php echo get_lzb_meta( 'control_meta_name' ); ?>
</p>