我使用了CCTM插件,我创建了几个自定义帖子类型。在每种帖子类型中,都有一个名为location的自定义字段。
我需要按位置过滤帖子列表 - 具体取决于登录用户。
例如,有35个帖子具有共同的位置名称(在自定义字段中设置): 20个帖子=位置是“日本” 15个帖子=位置是“韩国”
当管理员登录时,他应该会看到所有35个帖子。 当japan_admin登录时,他应该只看到20个帖子,位置名称为“日本”的帖子。 当korea_admin登录时,他应该只看到15个帖子,位置名称为“韩国”的帖子。
请帮助并分享有关如何执行此操作的任何想法。我今天搜索了很多,发现没有可用的插件。可能需要做wp钩子吗?
答案 0 :(得分:1)
首先添加额外的联系人字段名称country。那么下面的代码可以帮助你。
<?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;
?>