corsonr
1/27/2013 - 11:18 AM

pre_get_posts

pre_get_posts

<?php

// Load our function when hook is set
add_action( 'pre_get_posts', 'rc_modify_query_exclude_category' );

// Create a function to excplude some categories from the main query
function rc_modify_query_exclude_category( $query ) {

	// Check if on frontend and main query is modified
    if ( ! is_admin() && $query->is_main_query() && ! $query->get( 'cat' ) ) {
        $query->set( 'cat', '-5' );
    } // end if
}