certainlyakey
1/24/2015 - 9:59 AM

Wordpress - Change main query parameters

Wordpress - Change main query parameters

//Change main query parameters (for default archive pages or by url variables)
function change_query_parameters( $query ) {
	if ( is_admin() || ! $query->is_main_query() ) 
		return;

  //Check if a url variable is present
	if (get_query_var('allevents') || get_query_var('allevents') === 'true' || is_tax('eventlocation')) {
		$query->set( 'posts_per_page', 50 );
		$query->set( 'order' , 'DESC' );
	}
	
	if ( is_post_type_archive('event')) {
		$query->set( 'orderby' , 'menu_order' );
		$query->set( 'order' , 'ASC' );
		return $query;
	}

}
add_action( 'pre_get_posts', 'change_query_parameters', 1 );