Skip to content

Instantly share code, notes, and snippets.

@jester1979
Created January 6, 2018 10:47
Show Gist options
  • Save jester1979/709e202a341ca2461539e241c88b25c4 to your computer and use it in GitHub Desktop.
Save jester1979/709e202a341ca2461539e241c88b25c4 to your computer and use it in GitHub Desktop.
Preview archive
<?php
add_action( 'pre_get_posts', 'fpl_maybe_alter_main_query' );
function fpl_maybe_alter_main_query( $query ) {
//only perform this action on the main query on the frontend
if ( $query->is_main_query() && ( ! is_admin() ) ) {
//only do this for logged in users
if ( is_user_logged_in() ) {
//only do this when a preview is being requested
if ( isset( $_GET['preview'] ) && ( $_GET['preview'] == true ) ) {
$query->set( 'post_status', 'any' );
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment