Display post status drop down by user capability

2019-09-09 05:59发布

I want to prevent post status by user capability. Like 'draft' and 'pending' status display when author is logged in and 'publish' status display when editor is logged in.

标签: wordpress
1条回答
冷血范
2楼-- · 2019-09-09 06:58

You can try this:

<?php
if ( is_user_logged_in() ) {
    $args = array( 'post_type' => 'post', 'post_status' => 'publish, pending, draft' );
} else {
    $args = array( 'post_type' => 'post', 'post_status' => 'publish' );
}
$wp_query = new WP_Query($args); while ( have_posts() ) : the_post(); ?>

     CONTENT

<?php endwhile; ?>
<?php wp_reset_postdata(); ?>
查看更多
登录 后发表回答