从无权访问此 post 的用户中删除 display-posts link post

Remove display-posts link post from users who do not have access this post

我想从 post 列表中删除用户无权访问的 post 中的 link。

我的页面显示所有 post link。但我想显示 post 的所有标题,但某些 post 仅显示没有 link 的文本,因为用户没有权限。

我的 post 列表是测验。我想让用户先完成第一个测验,然后才能访问第二个测验。

当前情况,如果用户在完成第一个测验之前访问第二个测验,它将直接进入错误页面。但我想删除 link 到错误页面,因此只显示文本。

但不是全部link。我的代码显示列表

    function favourites_content() {
echo do_shortcode ('[display-posts post_type="unit" meta_key="module-tag" meta_value="Summer Session" orderby="date" order="ASC"]');
            }

您只需要在 if 条件中放置您的角色名称而不是作者。

function favourites_content() {
 $user = wp_get_current_user();
 if ( in_array( 'author', (array) $user->roles ) ) {
    echo do_shortcode ('[display-posts post_type="unit" meta_key="module-tag" meta_value="Summer Session" orderby="date" order="ASC"]');
 }else
 {

    echo "Please do the login to for edit the post";
 }
}