WP_User_Query is Not Displaying Results

I'm trying to create a table with a list of users and it only seems to work when I have it set up like this:

$user_report_query = new WP_User_Query( array(
    'role' = 'Administrator' 
) );

The array I'm trying to use is:

$args = array (
    'role'   = 'Participant',
    'order'  = 'ASC',
);

Participant is a custom role which has already been set up. I can select the role when creating users from the role dropdown menu. But any time i try to edit the query to use the array argument

$user_report_query = new WP_User_Query( $args );

it tells me no users have been found

if ( ! empty( $user_report_query-results ) ) {
    //display users
} else { 
    echo 'No users found.';
}

It only seems to work when I have the role as Administrator. As far as I can tell this is a basic WordPress user query so i shouldn't be having any problems with it. Any idea what it might be?

Topic wp-user-query Wordpress

Category Web


Here is a basic example of a user query I'm using that is working. Please note that I am using the role__in argument instead of the role argument. I'm not sure why the role argument wouldn't work for you but I know this code works so hopefully it will work for you as well.

$args = array(
    'role__in' => array('Subcriber', 'Editor'),
); // End Args
if ($args){
    $user_query = new WP_User_Query( $args );
}

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.