0

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?

0

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 );
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.