Last active
February 8, 2017 08:49
-
-
Save gatespace/74ec5299cf9b31e4090e1c520ab4655e to your computer and use it in GitHub Desktop.
WordPress 管理画面でカスタム投稿タイプの投稿一覧にカスタムタクソノミーの絞込をつける ref: http://qiita.com/gatespace/items/39a030c0303f6e82d35d
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_action( 'restrict_manage_posts', 'add_term_dropdown', 10, 2 ); | |
function add_term_dropdown( $post_type ) { | |
if ( 'session' == $post_type ) { // カスタム投稿タイプ 'session' の場合 | |
$term_slug = get_query_var( 'session_track' ); | |
wp_dropdown_categories( array( | |
'show_option_all' => __( 'All Tracks', 'my_theme' ), | |
'selected' => $term_slug, // 絞り込んだあとそのタームが選択されている状態を維持 | |
'name' => 'session_track', // select の name 属性 | |
'taxonomy' => 'session_track', // カスタムタクソノミーのスラッグ | |
'value_field' => 'slug', // option の value属性の中身を何にするか | |
)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment