我运行一个多个作者Wordpress网站与数千帖子。为了突出好帖子,我通过只有管理员可以设置的特定标签来过滤它们。例如featured
,front page
等。限制用户使用特定标签的技术,不会擦除标签
为了避免我的作者自己选择这些标签,我使用了以下脚本。如果用户选择了禁止标签,则一旦他们点击发布按钮,它将被删除。评论是为了方便:
add_action('save_post', 'remove_tags_function', 10, 1); //whenever a post is saved, run the below function
function remove_tags_function($post_id){
if(!current_user_can('manage_options')){ // if the logged in user cannot manage options (only admin can)
$post_tags = wp_get_post_terms($post_id, 'post_tag', array('fields'=>'names')); //grab all assigned post tags
$pos = array_search('tag-to-be-deleted', $post_tags); //check for the prohibited tag
if(false !== $pos) { //if found
unset($post_tags[$pos]); //unset the tag
wp_set_post_terms ($post_id, $post_tags, 'post_tag'); //override the posts tags with all prior tags, excluding the tag we just unset
}
}//end if. If the current user CAN manage options, the above lines will be skipped, and the tag will remain
}
这个解决方案存在一个主要问题。发布帖子后,管理员会给它一个featured
标签 - 但是如果原始作者会对其帖子进行更新,该标签将会消失。你明白这个问题吗?
许多作者喜欢对他们的帖子进行修改,特别是在评论中收到反馈意见时,以及与新闻相关的帖子类型,这些帖子需要经常更新。
你可以提出什么解决方案来解决这种情况?管理员需要能够提供特色标签,如果作者更新他们的帖子,标签应该保留。什么是拼图...
有趣。过滤工作如何?例如,目前,我可以通过将**&tag = random_tag **添加到URL来轻松过滤帖子。如果我使用自定义分类标准,类似的方法是否可行? –
@GaryWoods对不起,我可能一直不清楚我的回答(我已添加说明)。我只意味着不要为您的管理员属性使用标签。您的标签系统仍然保持不变。将你的“精选”,“头版”等分类到分类法中。 –
只是为了澄清,如果我将**精选**添加到定制分类中,它将如何工作?我如何列出已被选为特色的所有帖子?通过添加到URL可以工作吗?例如,我目前通过为URL添加&tag = featured来过滤特色。 –