按用户角色类型查询

时间:2017-01-05 00:31:14

标签: wordpress

我一直试图通过wordpress中的用户角色类型来制定查询方式,并且一直在使用我在Stack Overflow上找到的以下代码,但它并不适用于我:

        <?php
            $friends = get_users( array( 'role' => 'mns' ) );
        $friend_ids = array();

            foreach( $friends as $friend ) 
                $friend_ids[] = $friend->ID;

            $news = new WP_Query( array( 'author' => implode( ',', $friend_ids ), 'post_type' => 'roleplays', ) );
        ?>
        <?php if ( $news->have_posts() ) : while ( $news->have_posts() ) : $news->the_post(); ?> 
            <?php the_title(); ?>
        <?php endwhile; ?>
        <?php endif; ?>

循环收集自定义帖子类型中的所有帖子,但不会仅显示特定角色类型的帖子。

有什么想法吗?

提前致谢。

约什

1 个答案:

答案 0 :(得分:0)

你是否包括&#34; wp_reset_postdata();&#34;?使用the_post()时,应使用wp_reset_postdata()以确保不会出现意外结果。除此之外,我不知道导致问题的原因。是否有其他可能干扰的自定义PHP代码或插件?

相关问题