Wordpress发布在哪里?

Wordpress发布在哪里?,wordpress,filter,permissions,Wordpress,Filter,Permissions,我正在尝试设置一个wordpress站点,它使用私有/公共帖子来隐藏未登录用户的私有帖子,并允许作者查看所有用户的私有帖子 我正在尝试使用“posts\u where”过滤器进行设置,但无法使其工作 这是我的循环/查询代码,请注意,我需要在页面上使用两个循环来过滤私人帖子。我还允许作者在functions.php中查看私人帖子 <?php // filter private posts in user not permitted to view function privates_cont

我正在尝试设置一个wordpress站点,它使用私有/公共帖子来隐藏未登录用户的私有帖子,并允许作者查看所有用户的私有帖子

我正在尝试使用“posts\u where”过滤器进行设置,但无法使其工作

这是我的循环/查询代码,请注意,我需要在页面上使用两个循环来过滤私人帖子。我还允许作者在functions.php中查看私人帖子

<?php
// filter private posts in user not permitted to view
function privates_control($where) {
    if( current_user_can('read_private_posts')) return $where;
    global $wpdb;
    return " $where AND {$wpdb->posts}.post_status != 'private' "; // or add your     
custom status
}
$feature_args =  array('post_type' => array( 'post', 'work', 'people', 'events' ),    
'posts_per_page' => -1,
                    'orderby' => 'date', 'order' => 'DSC');
$feature_query = new WP_Query();
add_filter('posts_where', 'privates_control');
$feature_query->query($feature_args);
?>

<?php if ($feature_query->have_posts()) : while ($feature_query->have_posts()) :  
$feature_query->the_post(); ?>

<?php the_title(); ?>

<?php endif;?>
<?php wp_reset_query();?>
<?php wp_reset_postdata();?>

<?php
 // this is the first loop
$box_args =  array('post_type' => array( 'post', 'work', 'people', 'events' ),    
'posts_per_page' => -1,
                'orderby' => 'date', 'order' => 'DSC');
$boxes_query = new WP_Query();
add_filter('posts_where', 'privates_control');
$boxes_query->query($box_args);
?>
// this is the first loop
<?php if ($boxes_query->have_posts()) : while ($boxes_query->have_posts()) :  
$boxes_query->the_post(); ?>

  <?php the_title(); ?>

<?php endif;?>
<?php wp_reset_query();?>
<?php wp_reset_postdata();?>

设置后,您可以将其添加到
$args
(或
$feature\u args
)中:

if ( is_user_logged_in() ) {
  // this will add argument of showing also private to all logged in users
  // or any other condition ou want 
  $args['post_status'][] = 'private';
}

好的,所以不要用柱子钩?只是一个有条件的简单WP_查询?没有一种方法可以实现。使用你觉得更舒服的东西。