Skip to content

Instantly share code, notes, and snippets.

@chrisguitarguy
Created November 6, 2011 17:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrisguitarguy/1343219 to your computer and use it in GitHub Desktop.
Save chrisguitarguy/1343219 to your computer and use it in GitHub Desktop.
Allow admins to see draft posts on the front end
<?php
/*
Plugin Name: Admin Can View Any Post Type
Description: Allow admins to see can post type
Author: Christopher Davis
Author URI: http://www.christopherguitar.net/
*/
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';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment