Fix future posts hook affecting other post types

This commit is contained in:
Brian Miyaji
2018-01-30 12:21:05 +11:00
parent 114ed53ddf
commit 6f5fd5fa5e

View File

@@ -165,16 +165,22 @@ function sportspress_pre_get_posts( $query ) {
$query->set( 'orderby', 'menu_order' );
$query->set( 'order', 'ASC' );
endif;
elseif ( 'sp_event' == $post_type ):
elseif ( $query->is_main_query() ):
if ( 'sp_event' == $post_type ):
$GLOBALS[ 'wp_post_statuses' ][ 'future' ]->public = true;
elseif ( isset( $query->query[ 'sp_venue' ] ) ):
$query->set( 'post_type', 'sp_event' );
$GLOBALS[ 'wp_post_statuses' ][ 'future' ]->public = true;
endif;
return $query;
endif;
}
add_filter('pre_get_posts', 'sportspress_pre_get_posts');
add_action('pre_get_posts', 'sportspress_pre_get_posts');
function remove_sportspress_pre_get_posts() {
remove_action( 'pre_get_posts', 'sportspress_pre_get_posts' );
$GLOBALS[ 'wp_post_statuses' ][ 'future' ]->public = false;
}
add_action( 'wp', 'remove_sportspress_pre_get_posts' );
function sportspress_show_future_posts( $where, $that ) {
global $wpdb;