WordPress的管理员:基于用户登录筛选帖子

问题描述:

我使用了CCTM插件,并且我创建了几个自定义的帖子类型。在每个帖子类型中,都有一个名为location的自定义字段。WordPress的管理员:基于用户登录筛选帖子

我需要按位置过滤帖子列表 - 取决于登录的用户。

例如,有35个职位与常见位置名称(如在自定义字段设置): 20帖=位置是“日本” 15帖=位置是“韩国”

当管理日志中,他应该看到所有35个职位。 当japan_admin登录时,他只能看到20个帖子,位置名称为“日本”。 korea_admin登录时,只能看到15个帖子,位置名称为“韩国”。

请帮助和分享如何做到这一点的任何想法。今天我搜索了很多,发现没有可用的插件与此相关。可能需要做wp钩子?

先添加一个额外的联系人提交国名。那么下面的代码会帮助你。

<?php 
function my_user_contactmethods($user_contactmethods){ 
$user_contactmethods ['coutry'] = 'Coutry'; 
return $user_contactmethods ; 
} 
add_filter('user_contactmethods','my_user_contactmethods'); 

global $current_user; 
get_currentuserinfo(); 
$location = $current_user->coutry; 

if(current_user_can('manage_sites')){ 
query_posts('per_page_posts=-1&post_type=all you post type name'); 
}elseif($location = 'Japan'){ 
    query_posts('per_page_posts=-1&post_type=all you post type wanna show the japanese guys'); 
}elseif($location = 'Korea'){ 
query_posts('per_page_posts=-1&post_type=all you post type wanna show the korean  guys'); 
} 
while(have_posts()):the_post(); 
//normal code ... 
endwhile; 
?>