Site logo

[Resolved] Query Loop of User Category?

Home Forums Support [Resolved] Query Loop of User Category?

Home Forums Support Query Loop of User Category?

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #2600719
    Tom

    Hi
    I have GenerateBlocks Pro.
    I need to make a listing with users of a certain category.

    Its that possible?

    Thanks.
    Tom

    #2600879
    David
    Staff
    Customer Support

    Hi there,

    what is a User Category ?

    #2601097
    Tom

    User roles like admin, editor, etc. Or one created with a plugin like Advanced Access Manager.

    #2601392
    Ying
    Staff
    Customer Support

    Hi Tom,

    As the user is not a custom post type, so query loop can not achieve what you are looking for unfortunately.

    #2601824
    Tom

    OK.
    I wonder how Bricks does it. They have a query loop for users.

    #2602357
    Ying
    Staff
    Customer Support

    Query loop block can not achieve query users, it will require custom coding.

    However, you can use something like this to create a shortcode [my_user_list]:

    add_shortcode( 'my_user_list', function() {
        ob_start();
      // Retrieve all users with the "admin" role
    $args = array(
        'role' => 'administrator',
        'orderby' => 'user_nicename',
        'order' => 'ASC'
    );
    $users = get_users( $args );
    
    foreach ( $users as $user ) {
        echo '<p>' . esc_html( $user->display_name ) . '</p>';
    }
    
    // Retrieve all users with the "Contributor" role
    $args = array(
        'role' => 'contributor',
        'orderby' => 'user_nicename',
        'order' => 'ASC'
    );
    $users = get_users( $args );
    
    foreach ( $users as $user ) {
        echo '<p>' . esc_html( $user->display_name ) . '</p>';
    }
    
        return ob_get_clean();
    } );
    #2602488
    Tom

    Thanks!

    #2603241
    Ying
    Staff
    Customer Support

    No Problem 🙂

Viewing 8 posts - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.