Skip to content

Instantly share code, notes, and snippets.

@gatespace
Last active February 8, 2017 08:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gatespace/74ec5299cf9b31e4090e1c520ab4655e to your computer and use it in GitHub Desktop.
Save gatespace/74ec5299cf9b31e4090e1c520ab4655e to your computer and use it in GitHub Desktop.
WordPress 管理画面でカスタム投稿タイプの投稿一覧にカスタムタクソノミーの絞込をつける ref: http://qiita.com/gatespace/items/39a030c0303f6e82d35d
<?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