Codex tools: Log in
Languages: English • 日本語 • (Add your language)
Contents |
This function enables someone to hook into pre_get_posts and modify only the main query. This is a boolean function, meaning it returns either TRUE or FALSE. NOTE: admin screens also have a main query and this function can be used to detect it there.
<?php is_main_query(); ?>
This tag does not accept any parameters.
add_action( 'pre_get_posts', 'foo_modify_query_exclude_category' );
function foo_modify_query_exclude_category( $query ) {
if ( ! is_admin() && $query->is_main_query() && ! $query->get( 'cat' ) )
$query->set( 'cat', '-5' );
}
Since: 3.3
is_main_query() is located in wp-includes/query.php.