Skip to:
Content
Pages
Categories
Search
Top
Bottom

query ALL users with Role as Editor


  • Glenn
    Participant

    @rglennnall

    I’ve been trying for hours to create the proper query for all users with a particular Role

    can someone please help me with this?

    thanks
    GN

Viewing 2 replies - 1 through 2 (of 2 total)

  • shanebp
    Moderator

    @shanebp

    $subscribers = get_users( 'fields=ID&role=subscriber' );

    $subscribers will be an array of just the IDs of all subscribers.

    https://codex.wordpress.org/Function_Reference/get_users


    Glenn
    Participant

    @rglennnall

    thanks, this gets me the members that i want – i’m trying to put this in the members-loop

    this is failing to get some of the members for some reason:

    
     while ( bp_members() ) : bp_the_member(); 
    	
    	$user = new WP_User( bp_get_member_user_id() );
    	if ($user->roles[0] == 'subscribers') :
    

    this gets me all of them, but when i put it in the loop, it repeats the “students” each number of members

    
     while ( bp_members() ) : bp_the_member(); 
    	$subscribers = get_users( 'fields=ID&role=subscribers' );
    
    ?>
    
    <li class="kleo-masonry-item">
        	<div class="member-inner-list animated animate-when-almost-visible bottom-to-top">
            <div class="item-avatar rounded">
              <a href="<?php bp_member_permalink(); ?>"><?php bp_member_avatar(); ?></a>
              <?php do_action('bp_member_online_status', bp_get_member_user_id()); ?>
            </div>
    
    [ ................. ]
    
    

    would you mind giving me a hand getting this looped properly with the correct member data? i’d sure appreciate it – it’s been a year or so since i was really immersed in PHP and i don’t know BP at all…

    thanks so much
    GN

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘query ALL users with Role as Editor’ is closed to new replies.
Skip to toolbar