ACF User Field Bricks PHP Query

In the Bricks Facebook group a user asks:

my end goal was to create a set of cards that would display the Users that are in an ACF User field as a set of cards for my employee directories.

This Pro tutorial provides the steps to set the Bricks query type to the built-in Users, enable the PHP query editor and add the PHP code for setting include parameter to an array of selected user IDs for the current post.

CPT: department

Custom field: staff_members (user) with Select Multiple enabled and Return format of array.

When editing a specific Department post:

After implementing the tutorial:

Step 1

Edit single Department template with Bricks.

Inside a Section’s Container, add a Block and enable query loop.

Enable PHP query editor and paste:

// Get the selected staff members from ACF field
$staff_members = get_field( 'staff_members' );

if ( $staff_members ) {
	return [
		'include' => wp_list_pluck( $staff_members, 'ID' ),
		'orderby' => 'display_name',
		'order'   => 'ASC',
		'number'  => -1 // Return all matched users
	];
} else {
	return [
		'include' => [ -1 ],
		'number'  => -1 // Return all matched users
	];
}

Add a h3 Heading inside the Block set to

{wp_user_display_name}

Add any other elements as needed and map them to user-related Bricks’ dynamic data tags.