LoginSignup
2
6

More than 5 years have passed since last update.

[WordPress]管理画面にタクソノミーの絞り込みを追加

Last updated at Posted at 2016-12-27
functions.php
add_action('restrict_manage_posts', function($post_type) {
    $taxonomy = [];
    if ( $post_type == 'post_typeA' ) {
        $taxonomy['taxonomyAA'] = 'ラベル';
        $taxonomy['taxonomyAB'] = 'ラベル';
    } elseif ( $post_type == 'post_typeB' ) {
        $taxonomy['taxonomyBA'] = 'ラベル';
    }
    if ( empty($taxonomy) ) return;
    foreach ($taxonomy as $k => $v) {
        $selected = get_query_var($k);
        wp_dropdown_categories([
                'show_option_all' => "すべての{$v}",
                'selected' => $selected,
                'name' => $k,
                'taxonomy' => $k,
                'value_field' => 'slug'
        ]);
    }
}, 10, 2);

件数やページネーションも反映させるには
おそらくpre_get_postsとかparse_queryのフックにも引っ掛ける必要があると思われ

2
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
6