可以使用wp\\u parse\\u args()将参数合并到默认查询中
// Define the default query args
global $wp_query;
$defaults = $wp_query->query_vars;
// Your custom args
$args = array(\'cat\'=>-4);
// merge the default with your custom args
$args = wp_parse_args( $args, $defaults );
// query posts based on merged arguments
query_posts($args);
尽管如此,我认为更优雅的方法是使用pre\\u get\\u posts()操作。这会在进行查询之前修改查询,以便查询不会运行两次。
签出:
http://codex.wordpress.org/Custom_Queries#Category_Exclusion
基于该示例,我将把类别4从索引中排除,并将其放在函数中。php:
add_action(\'pre_get_posts\', \'wpa_44672\' );
function wpa_44672( $wp_query ) {
//$wp_query is passed by reference. we don\'t need to return anything. whatever changes made inside this function will automatically effect the global variable
$excluded = array(4); //made it an array in case you need to exclude more than one
// only exclude on the home page
if( is_home() ) {
set_query_var(\'category__not_in\', $excluded);
//which is merely the more elegant way to write:
//$wp_query->set(\'category__not_in\', $excluded);
}
}