0

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 {

    }
    ?>
2

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.

  • 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

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.