【问题标题】:query post to different role users in wordpress在wordpress中查询不同角色用户的帖子
【发布时间】:2017-03-26 10:48:36
【问题描述】:

是否可以向不同角色的用户显示不同的帖子?我需要这样的东西

用户 A => 发布 A ||

用户 B => 帖子 B

我不能使用 UserID,因为会有很多用户。我在想这样的事情

<?php
if ( is_userA_logged_in() ) {
    echo 'Welcome A user!'; //here comes the query
} elseif ( is_userB_logged_in() ) {
    echo 'Welcome B user!'; // here comes the query
}
?>

我正在阅读法典,但我只找到了is_admin(),我该如何调用新角色?

我会在 functions.php 中创建新角色

    <?php 
add_role('userA', 'User A', array(
    'read' => true, // True allows that capability
    'edit_posts' => false,
    'delete_posts' => false, // Use false to explicitly deny
));?>

【问题讨论】:

    标签: wordpress-theming wordpress


    【解决方案1】:

    参见current_user_can 函数。

    if ( current_user_can( $role ) )
        $q = get_query();
    

    另外,检查get_currentuserinfoget_userdata 等函数。

    【讨论】:

      猜你喜欢
      • 2016-04-29
      • 2023-04-11
      • 1970-01-01
      • 1970-01-01
      • 2023-03-26
      • 2020-08-08
      • 2017-09-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多