Display post status drop down by user capability

2019-09-09 05:57发布

问题:

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.

回答1:

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(); ?>


标签: wordpress