最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

user access - Limit post display to post authors and create an exception for specific pages

programmeradmin2浏览0评论

I'm trying to limit the display of the content to authors and need to make specific pages viewable by everyone (i.e Dashboard / Data entry ...) Any suggestions on how to add specific rules to display specific pages to all logged-in users?

Thanks a bunch

//limit post display to post authors (excludes admins)
function shapeSpace_set_only_author($query) {
global $current_user;
if (!current_user_can('manage_options')) {
    $query->set('author', $current_user->ID);
}
}
add_action('pre_get_posts', 'shapeSpace_set_only_author');
发布评论

评论列表(0)

  1. 暂无评论