最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

user meta - get_usersWP_User_Query returns empty when logged out

programmeradmin0浏览0评论

I have a fairly basic user query pulling staff members on a website I'm working on. When you are logged in to WordPress they are showing on the front-end. But when logged out they are not displaying. I did a var_dump and it is returning empty when logged out. I cannot find any logical reason for this. I tried without querying a role and it does the same thing.

<?php
$args = array(
    'role__in' => array('Staff')
);

// The Query
$user_query = get_users( $args );
var_dump($user_query);

// User Loop
    foreach ( $user_query as $user ) { ?>

        <?php $job_title = get_field('job_title', 'user_'. $user->ID ); ?>

        <div class="each-staff">

            <a class="staff-image" href="<?php echo get_author_posts_url( $user->id ); ?>"><img src="<?php echo esc_url( get_avatar_url( $user->ID ) ); ?>" /></a>
            <div class="staff-info">
                <h4 class="staff-name"><a href="<?php echo get_author_posts_url( $user->id ); ?>"><?php echo $user->display_name; ?></a></h4>
                <h5><?php echo $job_title; ?></h5>
            </div>

        </div>

    <?php }
?>  

I have a fairly basic user query pulling staff members on a website I'm working on. When you are logged in to WordPress they are showing on the front-end. But when logged out they are not displaying. I did a var_dump and it is returning empty when logged out. I cannot find any logical reason for this. I tried without querying a role and it does the same thing.

<?php
$args = array(
    'role__in' => array('Staff')
);

// The Query
$user_query = get_users( $args );
var_dump($user_query);

// User Loop
    foreach ( $user_query as $user ) { ?>

        <?php $job_title = get_field('job_title', 'user_'. $user->ID ); ?>

        <div class="each-staff">

            <a class="staff-image" href="<?php echo get_author_posts_url( $user->id ); ?>"><img src="<?php echo esc_url( get_avatar_url( $user->ID ) ); ?>" /></a>
            <div class="staff-info">
                <h4 class="staff-name"><a href="<?php echo get_author_posts_url( $user->id ); ?>"><?php echo $user->display_name; ?></a></h4>
                <h5><?php echo $job_title; ?></h5>
            </div>

        </div>

    <?php }
?>  
Share Improve this question asked Dec 19, 2019 at 11:02 Benjamin CuslidgeBenjamin Cuslidge 211 bronze badge
Add a comment  | 

1 Answer 1

Reset to default 1

I figured out the issue is with the plugin Advanced Access Manager we used to create the custom role for Staff. There is a setting by default:

User Level Filter Extend default WordPress core users and roles handling, and make sure that users with lower user level cannot see or manager users and roles with higher level.

This was causing them to not show on the front-end. Hope this helps if anyone comes across the same problem.

发布评论

评论列表(0)

  1. 暂无评论