如果你想修改提要,你应该钩住WordPress对每个页面请求所做的主查询。这里最好的钩子是pre_get_posts
. 此代码示例将连接到pre_get_posts
, 检查是否为提要,并添加post格式分类查询:
add_action( \'pre_get_posts\', \'wpse18412_pre_get_posts\' );
function wpse18412_pre_get_posts( &$wp_query )
{
if ( $wp_query->is_feed() ) {
$post_format_tax_query = array(
\'taxonomy\' => \'post_format\',
\'field\' => \'slug\',
\'terms\' => \'post-format-image\', // Change this to the format you want to exclude
\'operator\' => \'NOT IN\'
);
$tax_query = $wp_query->get( \'tax_query\' );
if ( is_array( $tax_query ) ) {
$tax_query = $tax_query + $post_format_tax_query;
} else {
$tax_query = array( $post_format_tax_query );
}
$wp_query->set( \'tax_query\', $tax_query );
}
}