Ok so I have multiple different page templates with a main query that I want to filter the loop for. In my example I try to use a function to filter the main loop of my site and also the main loop for the page 'new'. Now this works fine for the main page but makes the 'new' page return a 'page not found' not taking the custom template that's assigned to it. What's the right way to do this?
function fod_filter_main_query( $query ) {
if( is_front_page() && is_main_query() ) {
$query->set('meta_key', 'hotness');
$query->set('meta_value', 0 );
$query->set('meta_compare', '>');
$query->set('orderby', 'meta_value_num' );
$query->set('order', 'desc');
$query->set('cat', -1 );
$query->set('posts_per_page', 16 );
$query->set('post_type', array( 'post','fod_videos','fod_music','fod_articles', 'fod_albums' ));
} elseif ( is_page('new') && is_main_query() ) {
$query->set('cat', -1 );
$query->set('order', 'asc');
$query->set('posts_per_page', 16 );
$query->set('post_type', array( 'post','fod_videos','fod_music','fod_articles', 'fod_albums' ));
}
}
add_action('pre_get_posts', 'fod_filter_main_query', 9999);