WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a few custom post types on my website. One of these is a front page slider. I add some text, images, links and as soon as I publish the CPT appears as a slide and I'm a happy camper. The problem is when I need to preview the slide before it is live. I can preview that specific CPT post via the post preview button, but obviously I see the actual slide and not how the slide looks in that slider or gallery or archive.

I'm looking for a solution to preview the Drafts in an archive. Any help will be much appreciated.

share|improve this question
up vote 3 down vote accepted

The get_posts method of WP_Query is what does the heavy lifting as far as getting the posts to display. Before it does anything, however, there's a hook called pre_get_posts that you can hook into. The hooked function will receive a reference (pointer) to the current query object. So you can change the query vars to be whatever you'd like.


add_action( 'pre_get_posts', 'wpse33020_pre_get_posts' );
function wpse33020_pre_get_posts( $query_obj )
    // get out of here if this is the admin area
    if( is_admin() ) return;

    // if this isn't an admin, bail
    if( ! current_user_can( 'manage_options' ) ) return;

    // if this isn't your slide post type, bail
    if( ! isset( $query_obj->query_vars['post_type'] ) || 'slider' != $query_obj->query_vars['post_type'] ) return;

    // change our query object to include any post status
    $query_obj->query_vars['post_status'] = 'any';

You'll probably have to change your post_type from slider to whatever you slider CPT is named.

As a plugin: https://gist.github.com/1343219

share|improve this answer

Your Answer


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.