我有nhl新闻网站,我为每个季节创建自定义分类法(ex 2014-15)
function wptp_register_taxonomy() {
register_taxonomy( 'season', 'post',
array(
'labels' => array(
'name' => 'Seasons',
'singular_name' => 'Season',
'search_items' => 'Search Season',
'all_items' => 'All Season',
'edit_item' => 'Edit Season',
'update_item' => 'Update',
'add_new_item' => 'Add New Season',
'new_item_name' => 'New Season',
'menu_name' => 'Seasons',
),
'hierarchical' => true,
'sort' => true,
'args' => array( 'orderby' => 'term_order' ),
'rewrite' => array( 'slug' => 'season' ),
'show_admin_column' => true
)
);
}
add_action( 'init', 'wptp_register_taxonomy' );
add_filter('pre_get_posts','season_archive');
function better_editions_archive( $query ) {
if ( $query->is_tax( 'season' ) && $query->is_main_query() ) {
$query->set( 'post_type', array( 'post' ) );
$query->set( 'tax_query',
array(
'relation' => 'OR',
array(
'taxonomy' => 'season',
'field' => 'slug',
'terms' => 'intl',
'operator' => 'IN'
)
)
);
}
return $query;
}
EX当我想获得2013-2014帖子时:
http://localhost/nhl/news/?season=20132014
现在我想要的是当我转到没有分类的类别新闻时
http://localhost/nhl/news/
仅显示2014-2015的当前季节帖子,而不使用自定义分类标本
谢谢