我希望在循环中包含一个过滤器,以便只显示来自具有特定用户角色的作者的帖子。我想要在某个类别中显示它们,例如“已验证的作者”,所以我需要检查这是否也是循环中的正确类别。
这是我得到的:
functions.php
function get_author_role()
{
global $authordata;
$author_roles = $authordata->roles;
$author_role = array_shift($author_roles);
return $author_role;
}类别模板中的循环
<?php
if(have_posts()) : while(have_posts()) : the_post();
//how to check if author = specific role and check if category 'verifiedauthors" ?
endwhile;endif;
?>发布于 2014-10-23 16:50:08
您可以将作者查询添加到您的循环。
// Example
$atuhors_array = array( 1,4,5,3 );
$query = new WP_Query( array( 'author__in' => $authors_array ) );一旦你必须创建数组并添加,我们就会寻找这个数组的作者。
$blogusers = get_users( 'blog_id=1&orderby=nicename&role=subscriber' );
// Array of WP_User objects.
foreach ( $blogusers as $user ) {
$authors_array[]= $user->ID;将author添加到数组后,现在可以使用author query。
https://stackoverflow.com/questions/26523267
复制相似问题