How to query users?

Hello,

I’d like to display 7 profile images from our team from various user roles in random order.
Unfortunately it doesn’t work yet. What am I doing wrong here?

For the profile picture I’m using {wp_user_picture} in an image element.

Thanks

What doesn’t work? What result do you get?
I note you have query relation = ‘or’ - but nothing set. I’d clear that just in case.
Then do a ‘blank’ query for users (no filter/meta/roles). DO you get users?
If you do, add each element (e.g. which roles) - until it breaks. Then let us know when that was and we can maybe look at why.

1 Like

I get the output “fds” which means no results. I’ve cleared ‘OR’.
Even without any filters/meta/roles, I don’t get any users. It still shows ‘no results’.

There are multiple users registered.

Odd. If I start with a blank page, add this section, and on the DIV add a query where I set nothing but ‘users’ as query type… I get my list of users.
Screenshot 2023-06-04 at 10.07.13
{wp_user_display_name} in the heading gives the name, and {wp_user_picture} the image.

Are your users standard WP Users? Are there other queries on the page? Any plugins (like membership) that might alter behaviour for user profiles? Any other plugins etc. Are you able to get the list on a new, blank page with just the query?

You could maybe drop this in a code-block on the page, to see if WP itself ‘sees’ the users.

<?php
$blogusers = get_users( array( 'role__in' => array( 'author', 'editor' ) ) );
foreach ( $blogusers as $user ) {
    echo '<span>' . esc_html( $user->display_name ) . '</span>';
}
?>

Don’t forget to enable ‘run code’.

I’m afraid I don’t have many other ideas… I’d be looking for a plugin/code conflict -as plain Bricks should return users with the query you have.

Thanks! Adding the provided code gives me the list of users on that page.

Creating a new test page and adding the user query also gives me the list of users.

On my original page, I have a code which I disabled being executed. No difference.
Other than that there’s only text on that page.

My original page looks like this:
image

I have now copied the section with the user query from the test page over to my original page.
image
It works! User names are being displayed.

From that copied section, I have now moved only the Div with the user query above my initial not working user query Div “Team Members”, and it works. The users are being displayed where I need them.
image

Those two Divs, sitting next to each other, have the same query, also no settings/conditions/classes etc.

I have now created a new Div 3 below and added a user query. It works again.
image

I just don’t understand what makes it work in a new Div but not in the one I’ve added before.

Thanks for helping me make this work!

Lastly, is there a way or workaround to display those users in a random order, because the order by field doesn’t have that option.

I think this would need a custom query. I have some vague notion that WP doesn’t have a random option built in.

1 Like