Skip to content

Instantly share code, notes, and snippets.

@mmilosheski
Last active May 18, 2017 12:36
Show Gist options
  • Save mmilosheski/94e8e103cb97ed75b2f4eaf3804eea8d to your computer and use it in GitHub Desktop.
Save mmilosheski/94e8e103cb97ed75b2f4eaf3804eea8d to your computer and use it in GitHub Desktop.
/*
modifiying the general wp_query and adding the suppress filters to be off all the time
*/
add_action( '__before_loop' , 'modify_main_wp_query1' );
add_action( '__after_loop' , 'modify_main_wp_query1' );
function modify_main_wp_query1() {
global $wp_query;
switch ( current_filter() ) {
case '__before_loop':
$args = array(
'suppress_filters' => false
);
//execute the
query_posts( $args );
//set global $wp_query object back initial values for boolean and front page id
$wp_query->is_page = true;
$wp_query->is_singular = true;
$wp_query->query_vars['p'] = $front_page_id;
$wp_query->query_vars['page_id'] = $front_page_id;
break;
case '__after_loop':
//reset the custom query
wp_reset_query();
break;
}
}
function modify_main_wp_query( $query ) {
$query->query_vars['suppress_filters'] = false;
}
add_action( 'pre_get_posts', 'modify_main_wp_query' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment