Archived topic
Query Loop of User Category?
7 replies · Started by Tom on April 7, 2023
Hi
I have GenerateBlocks Pro.
I need to make a listing with users of a certain category.
Its that possible?
Thanks.
Tom
Hi there,
what is a User Category ?
User roles like admin, editor, etc. Or one created with a plugin like Advanced Access Manager.
Hi Tom,
As the user is not a custom post type, so query loop can not achieve what you are looking for unfortunately.
OK.
I wonder how Bricks does it. They have a query loop for users.
Query loop block can not achieve query users, it will require custom coding.
However, you can use something like this to create a shortcode [my_user_list]:
add_shortcode( 'my_user_list', function() {
ob_start();
// Retrieve all users with the "admin" role
$args = array(
'role' => 'administrator',
'orderby' => 'user_nicename',
'order' => 'ASC'
);
$users = get_users( $args );
foreach ( $users as $user ) {
echo '<p>' . esc_html( $user->display_name ) . '</p>';
}
// Retrieve all users with the "Contributor" role
$args = array(
'role' => 'contributor',
'orderby' => 'user_nicename',
'order' => 'ASC'
);
$users = get_users( $args );
foreach ( $users as $user ) {
echo '<p>' . esc_html( $user->display_name ) . '</p>';
}
return ob_get_clean();
} );
Thanks!
No Problem :)