Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm working on a project where editors need to see the pending posts on the homepage to improve them before publish.

Maybe there is something to do with the loop in this way:

If editors logged:

if ( current_user_can('edit_post') ) {
    display the pending posts
}

The args to display publish and pending posts:

$args = array( 'post_type' => 'post', 'post_status' => 'publish, pending' );

The completed loop:

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

…the content here...

<?php endwhile; ?>
<?php wp_reset_postdata(); // reset the query ?>

It work for me.

Do you think this is correct?

Maybe the code can be improved.

Thanks for the help.

share|improve this question
add comment

1 Answer

up vote 3 down vote accepted

I would filter pre_get_posts.

function allow_pending_posts_wpse_103938($qry) {
  if (!is_admin() && current_user_can('edit_posts')) {
    $qry->set('post_status', array('publish','pending'));
  }
}
add_action('pre_get_posts','allow_pending_posts_wpse_103938');

That should show pending posts to your editors for all of your queries on the front end. You can, of course, restrict is more if you'd like.

I'd add some code to mark the pending posts so your editors know at a glance what is pending.

share|improve this answer
    
Very nice. Well done. Thank a lot! –  jeromeM Jun 23 '13 at 16:58
1  
I reiterate, that will effect all queries on the front end. Be aware. –  s_ha_dum Jun 23 '13 at 16:59
    
Yes, exactly what I need. Thank again. –  jeromeM Jun 23 '13 at 19:30
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.