Created
January 6, 2018 10:47
-
-
Save jester1979/709e202a341ca2461539e241c88b25c4 to your computer and use it in GitHub Desktop.
Preview archive
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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