【问题标题】:Wordpress only show posts from specific author roleWordpress 仅显示来自特定作者角色的帖子
【发布时间】:2014-10-23 07:35:46
【问题描述】:

我想在循环中包含一个过滤器,因此只有具有特定用户角色的作者的帖子才会出现。我想在某个类别中展示它们,例如“经过验证的作者”,所以我还需要检查这是否是循环中的正确类别。

这是我得到的:

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;
?>

【问题讨论】:

  • 对不起,我的意思是创建的用户角色

标签: php wordpress loops


【解决方案1】:

您可以将作者查询添加到您的循环中。

// 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;

将作者添加到数组后,现在可以使用作者查询。

【讨论】:

  • 这是否意味着,我必须手动将所有作者添加到数组中才能将它们添加到“已验证”?我只想从某个用户角色中获取所有帖子.. 所以只显示来自例如订阅者的帖子
  • 所以 1,2,3,4 代表类别?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-04-11
  • 1970-01-01
  • 1970-01-01
  • 2012-08-21
  • 2010-12-03
  • 2012-02-08
  • 1970-01-01
相关资源
最近更新 更多