Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm able to list users by a single role only. When I try and add an array to the code below I just get a list of all authors. I'm sure that it is something straight forward that I'm missing.

Thanks

Josh

 <?php

            $roles = array('guest-teacher', 'president', 'core-faculty');

   $args  = array(
     'meta_key' => 'last_name',
     'role'     => $roles
    );

    $wp_user_query = new WP_User_Query($args);
    $wp_user_query->query_orderby = str_replace( 'user_login', 'lsjs_usermeta.meta_value', $wp_user_query->query_orderby );
    $wp_user_query->query();

    $authors = $wp_user_query->get_results();



    // Check for results;
    if (!empty($authors))
    {
        echo '<ul class="permanent">';
        // loop trough each author
        foreach ($authors as $author)
        {
            // get all the user's data
            $author_info = get_userdata($author->ID);
            $url = get_author_posts_url($author->ID);  

    ?>


        <h3><a href="<?php echo $url; ?>"><?php echo $author_info->last_name; ?></a></h3>

            <?php
        }
        echo '</ul>';
    } else {

    }
    ?>
share|improve this question

1 Answer 1

up vote 1 down vote accepted

Unfortunately, you cannot pass an Array of User Roles to WP_User_Query. The role argument only accepts a String, which is then cleared by a trim command.

See user.php on Line 495, where prepare handles the Query for the Constructor after parsing the $args.

share|improve this answer
    
Thanks. So it seems like roles also can't be excluded. –  Josh Feb 26 '13 at 12:40
    
Hm, I am not sure about that - try -role, but I think it won't work. –  fischi Feb 26 '13 at 12:48

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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