Title: wp_list_categories()のパラメータexclude_treeで複数除外できない
Last modified: 2016年9月15日

---

# wp_list_categories()のパラメータexclude_treeで複数除外できない

 *  解決済 [odmodm](https://ja.wordpress.org/support/users/odmodm/)
 * (@odmodm)
 * [10年、 11ヶ月前](https://ja.wordpress.org/support/topic/wp_list_categories%e3%81%ae%e3%83%91%e3%83%a9%e3%83%a1%e3%83%bc%e3%82%bfexclude_tree%e3%81%a7%e8%a4%87%e6%95%b0%e9%99%a4%e5%a4%96%e3%81%a7%e3%81%8d%e3%81%aa%e3%81%84/)
 * バージョン4.4においてwp_list_categories()の引数に指定するパラメータexcludeにて、
   カンマ区切りで複数指定した場合正しく除外されません。
 * wp_list_categories()内部において下記のように
    `$categories = get_categories( 
   $r );` と記述されている箇所でget_categories()に渡しているパラメータexclude_tree
   の値が4.3のころには単に文字列でしたが、4.4では配列となっていて、おそらくそれが
   原因で２つ目以降の除外指定したカテゴリが除外されずに取得されています。 これは
   不具合なのでしょうか。

15件の返信を表示中 - 1 - 15件目 (全16件中)

1 [2](https://ja.wordpress.org/support/topic/wp_list_categories%e3%81%ae%e3%83%91%e3%83%a9%e3%83%a1%e3%83%bc%e3%82%bfexclude_tree%e3%81%a7%e8%a4%87%e6%95%b0%e9%99%a4%e5%a4%96%e3%81%a7%e3%81%8d%e3%81%aa%e3%81%84/page/2/?output_format=md)
[→](https://ja.wordpress.org/support/topic/wp_list_categories%e3%81%ae%e3%83%91%e3%83%a9%e3%83%a1%e3%83%bc%e3%82%bfexclude_tree%e3%81%a7%e8%a4%87%e6%95%b0%e9%99%a4%e5%a4%96%e3%81%a7%e3%81%8d%e3%81%aa%e3%81%84/page/2/?output_format=md)

 *  [tg29359](https://ja.wordpress.org/support/users/tg29359/)
 * (@tg29359)
 * [10年、 10ヶ月前](https://ja.wordpress.org/support/topic/wp_list_categories%e3%81%ae%e3%83%91%e3%83%a9%e3%83%a1%e3%83%bc%e3%82%bfexclude_tree%e3%81%a7%e8%a4%87%e6%95%b0%e9%99%a4%e5%a4%96%e3%81%a7%e3%81%8d%e3%81%aa%e3%81%84/#post-188158)
 * 挙動としては確かに
 * `'exclude_tree'=>array(9,10)`
 * って編集して渡すと、カテゴリーID 9のカテゴリーツリーと 10のが消えますけど、
 * `'exclude_tree'=>'9,10'`
 * って編集して渡すと、カテゴリーID 9のツリーしか消えないですね。
 * 仮に下記のリファレンスの記事が最新版だとしたら、不具合だということになりますね。
   配列でもカンマかスペース区切りの文字列でもOK、みたいに書いてあるので。
 * > [Home](https://developer.wordpress.org/)
 * > ‘exclude_tree’
   >  (array|string) Array or comma/space-separated string of term
   > IDs to exclude, along with their descendants. See get_terms().
 *  トピック投稿者 [odmodm](https://ja.wordpress.org/support/users/odmodm/)
 * (@odmodm)
 * [10年、 10ヶ月前](https://ja.wordpress.org/support/topic/wp_list_categories%e3%81%ae%e3%83%91%e3%83%a9%e3%83%a1%e3%83%bc%e3%82%bfexclude_tree%e3%81%a7%e8%a4%87%e6%95%b0%e9%99%a4%e5%a4%96%e3%81%a7%e3%81%8d%e3%81%aa%e3%81%84/#post-188163)
 * tg29359さん
 * ご検証いただきありがとうございます。
 * 正確には
    4.3では ‘exclude_tree’ => ‘9,10’
 * 4.4では
    ‘exclude_tree’ => array( 0 => ‘9,10’ );
 * という形になっています。
    ここでの不具合報告だけでは不十分でしょうか。
 *  [tg29359](https://ja.wordpress.org/support/users/tg29359/)
 * (@tg29359)
 * [10年、 10ヶ月前](https://ja.wordpress.org/support/topic/wp_list_categories%e3%81%ae%e3%83%91%e3%83%a9%e3%83%a1%e3%83%bc%e3%82%bfexclude_tree%e3%81%a7%e8%a4%87%e6%95%b0%e9%99%a4%e5%a4%96%e3%81%a7%e3%81%8d%e3%81%aa%e3%81%84/#post-188165)
 * 私は最近ここに来るようになったばかりで、不十分かどうかはいまいちわかりませんが、
   WordPressの不具合管理は、直接的には、tracというシステムで行われている様で、確実
   に対応してもらうには、そちらに不具合報告した方がいいかもしれません。
 * [https://core.trac.wordpress.org](https://core.trac.wordpress.org)
 * また、tracを検索したら、既にこの件の不具合報告（チケットと呼ぶようです）が登録
   されいるかもしれません。もし登録されていたら、そのチケットに対してwatchという
   操作をすると、進展があった時にメールで連絡が来たりします。
 * ここでの報告だけでも、ここを見た他のメンバーの方がチケットを作成してくださること
   もあります。
 * 私自身は、この件に関してtracは検索しておりませんので、もしお急ぎでしたら、ご自身
   で検索していただけると、何かわかるかもしれません。
 *  [tg29359](https://ja.wordpress.org/support/users/tg29359/)
 * (@tg29359)
 * [10年、 10ヶ月前](https://ja.wordpress.org/support/topic/wp_list_categories%e3%81%ae%e3%83%91%e3%83%a9%e3%83%a1%e3%83%bc%e3%82%bfexclude_tree%e3%81%a7%e8%a4%87%e6%95%b0%e9%99%a4%e5%a4%96%e3%81%a7%e3%81%8d%e3%81%aa%e3%81%84/#post-188166)
 * あ、ちょっと待ってください、この挙動、もしかしたら仕様通りかもしれません。以下
   は4.4でもうまく動くんですよね？。
 *     ```
       'exclude_tree' => array(
       0 => '9,10'
       );
       ```
   
 * それって、配列の先頭要素が、リファレンスで言ってる「カンマで区切られた文字列」
   である、ってことだとも言えますよね。で、一方、私が例示した以下も、意図通り動く
   のは実際に確認しています。
 * `'exclude_tree'=>array(9,10)`
 * で、私が例示したのはカンマ区切り文字列じゃなく単なるidの配列です。つまり、リファレンス
   に書いてある通り、カンマ区切り文字列でも配列でも両方いけてる、ってことで、ある
   意味、仕様通りなんじゃないですか？。
    ただ、文字列で渡す時は、今までと微妙に渡し
   方が変わってます、ってだけで。
 *  トピック投稿者 [odmodm](https://ja.wordpress.org/support/users/odmodm/)
 * (@odmodm)
 * [10年、 10ヶ月前](https://ja.wordpress.org/support/topic/wp_list_categories%e3%81%ae%e3%83%91%e3%83%a9%e3%83%a1%e3%83%bc%e3%82%bfexclude_tree%e3%81%a7%e8%a4%87%e6%95%b0%e9%99%a4%e5%a4%96%e3%81%a7%e3%81%8d%e3%81%aa%e3%81%84/#post-188167)
 * ご返信いただき感謝いたします。
 * 4.4の場合は以下のようにget_categories()に値が渡されるため、”うまく動いておりま
   せん”。
 *     ```
       'exclude_tree' => array(
       　　　　　　　　　　　0 => '9,10'
       );
       ```
   
 * おそらくtg29359さんが記述された形となるべきなのでしょうね。
    tracは確認させて
   いただきましたが、英語がわからずいくつかのexclude_treeに関するバグ報告が今回の
   ものと同じであるかが区別できません。
 * ですので、もしこの件を報告してくださる方がいらっしゃればお願いしたいと思います。
 *  [tg29359](https://ja.wordpress.org/support/users/tg29359/)
 * (@tg29359)
 * [10年、 10ヶ月前](https://ja.wordpress.org/support/topic/wp_list_categories%e3%81%ae%e3%83%91%e3%83%a9%e3%83%a1%e3%83%bc%e3%82%bfexclude_tree%e3%81%a7%e8%a4%87%e6%95%b0%e9%99%a4%e5%a4%96%e3%81%a7%e3%81%8d%e3%81%aa%e3%81%84/#post-188168)
 * あ、失礼しました。以下は動いてないときの例だったのですね。だとすると、リファレンス
   の言ってる「カンマや空白区切り文字列も可」と合ってなくて不具合っぽい気はしますね。
 *     ```
       'exclude_tree' => array(
       0 => '9,10'
       );
       ```
   
 *  [gblsm](https://ja.wordpress.org/support/users/gblsm/)
 * (@gblsm)
 * [10年、 10ヶ月前](https://ja.wordpress.org/support/topic/wp_list_categories%e3%81%ae%e3%83%91%e3%83%a9%e3%83%a1%e3%83%bc%e3%82%bfexclude_tree%e3%81%a7%e8%a4%87%e6%95%b0%e9%99%a4%e5%a4%96%e3%81%a7%e3%81%8d%e3%81%aa%e3%81%84/#post-188170)
 * 4.4で変更された wp_list_categories() のコードに問題がありますね。
    変更内容と
   テストパターンが下記のリンク先で見られます。 [https://core.trac.wordpress.org/changeset/34696](https://core.trac.wordpress.org/changeset/34696)
   このテストパターンはarray形式の引数だけテストしていますが気づかなかったのでしょう。
 * # チケットのopen方法はどこを読めばわかるでしょうか。。。
 *  [gblsm](https://ja.wordpress.org/support/users/gblsm/)
 * (@gblsm)
 * [10年、 10ヶ月前](https://ja.wordpress.org/support/topic/wp_list_categories%e3%81%ae%e3%83%91%e3%83%a9%e3%83%a1%e3%83%bc%e3%82%bfexclude_tree%e3%81%a7%e8%a4%87%e6%95%b0%e9%99%a4%e5%a4%96%e3%81%a7%e3%81%8d%e3%81%aa%e3%81%84/#post-188171)
 * もう少しコードを眺めていくと、exclude_treeを本当に処理するget_terms()の中で、
   文字列形式をIDの配列へ変換するときに wp_parse_id_list() を使っていました。これ
   を wp_list_categories() のコードでも使えば正しく動きそうです。検証していません
   が、、、
 * wp_list_categories() の中：
 *     ```
       if ( $r['exclude_tree'] ) {
           // $exclude_tree = array_merge( $exclude_tree, (array) $r['exclude_tree'] );
           $exclude_tree = array_merge( $exclude_tree, wp_parse_id_list( $r['exclude_tree'] ) );
       }
   
       if ( $r['exclude'] ) {
           // $exclude_tree = array_merge( $exclude_tree, (array) $r['exclude'] );
           $exclude_tree = array_merge( $exclude_tree, wp_parse_id_list( $r['exclude'] ) );
       }
       ```
   
 *  トピック投稿者 [odmodm](https://ja.wordpress.org/support/users/odmodm/)
 * (@odmodm)
 * [10年、 10ヶ月前](https://ja.wordpress.org/support/topic/wp_list_categories%e3%81%ae%e3%83%91%e3%83%a9%e3%83%a1%e3%83%bc%e3%82%bfexclude_tree%e3%81%a7%e8%a4%87%e6%95%b0%e9%99%a4%e5%a4%96%e3%81%a7%e3%81%8d%e3%81%aa%e3%81%84/#post-188172)
 * gblsmさんご返信感謝いたします。
 * ご提示いただいた上記のコードをwp_list_categories()の中で使用してみたところ、
 *     ```
       [exclude_tree] => Array
               (
                   [0] => 7
                   [1] => 8
               )
       ```
   
 * という形で格納されるようになり、きちんと複数のカテゴリが除外されるようになりま
   した。
    検証結果のご報告です。
 *  [gblsm](https://ja.wordpress.org/support/users/gblsm/)
 * (@gblsm)
 * [10年、 10ヶ月前](https://ja.wordpress.org/support/topic/wp_list_categories%e3%81%ae%e3%83%91%e3%83%a9%e3%83%a1%e3%83%bc%e3%82%bfexclude_tree%e3%81%a7%e8%a4%87%e6%95%b0%e9%99%a4%e5%a4%96%e3%81%a7%e3%81%8d%e3%81%aa%e3%81%84/#post-188177)
 * とりあえずバグチケットを初めて投稿してみました。こんなのでいいんでしょうか。。。
   
   [https://core.trac.wordpress.org/ticket/35156](https://core.trac.wordpress.org/ticket/35156)
 *  [Hinaloe](https://ja.wordpress.org/support/users/hnle/)
 * (@hnle)
 * [10年、 10ヶ月前](https://ja.wordpress.org/support/topic/wp_list_categories%e3%81%ae%e3%83%91%e3%83%a9%e3%83%a1%e3%83%bc%e3%82%bfexclude_tree%e3%81%a7%e8%a4%87%e6%95%b0%e9%99%a4%e5%a4%96%e3%81%a7%e3%81%8d%e3%81%aa%e3%81%84/#post-188178)
 * 👍
 * Let’s attache your patch!
 * パッチやテストを投げてみませう!
 * [VVVを使ってWordPress本体のパッチを送る方法 | Firegoby](https://firegoby.jp/archives/5981)
 * [WordPress Core Unit Tests – Sal Ferrarello](http://salferrarello.com/wordpress-core-unit-test/)
 *  [gblsm](https://ja.wordpress.org/support/users/gblsm/)
 * (@gblsm)
 * [10年、 10ヶ月前](https://ja.wordpress.org/support/topic/wp_list_categories%e3%81%ae%e3%83%91%e3%83%a9%e3%83%a1%e3%83%bc%e3%82%bfexclude_tree%e3%81%a7%e8%a4%87%e6%95%b0%e9%99%a4%e5%a4%96%e3%81%a7%e3%81%8d%e3%81%aa%e3%81%84/#post-188179)
 * パッチを投げるまでは気力が続かないのでバグチケットにパッチをくっつけてきました。
   
   [https://core.trac.wordpress.org/attachment/ticket/35156/category-template.php.diff](https://core.trac.wordpress.org/attachment/ticket/35156/category-template.php.diff)
 *  [Hinaloe](https://ja.wordpress.org/support/users/hnle/)
 * (@hnle)
 * [10年、 10ヶ月前](https://ja.wordpress.org/support/topic/wp_list_categories%e3%81%ae%e3%83%91%e3%83%a9%e3%83%a1%e3%83%bc%e3%82%bfexclude_tree%e3%81%a7%e8%a4%87%e6%95%b0%e9%99%a4%e5%a4%96%e3%81%a7%e3%81%8d%e3%81%aa%e3%81%84/#post-188180)
 * (あっパッチを投げるってそういう意味で一応あってます)
 *  [Hinaloe](https://ja.wordpress.org/support/users/hnle/)
 * (@hnle)
 * [10年、 10ヶ月前](https://ja.wordpress.org/support/topic/wp_list_categories%e3%81%ae%e3%83%91%e3%83%a9%e3%83%a1%e3%83%bc%e3%82%bfexclude_tree%e3%81%a7%e8%a4%87%e6%95%b0%e9%99%a4%e5%a4%96%e3%81%a7%e3%81%8d%e3%81%aa%e3%81%84/#post-188181)
 * Merged in [[36005](https://core.trac.wordpress.org/changeset/36006)], [[36006](https://core.trac.wordpress.org/changeset/36006)]
   thx!
 *  [gblsm](https://ja.wordpress.org/support/users/gblsm/)
 * (@gblsm)
 * [10年、 10ヶ月前](https://ja.wordpress.org/support/topic/wp_list_categories%e3%81%ae%e3%83%91%e3%83%a9%e3%83%a1%e3%83%bc%e3%82%bfexclude_tree%e3%81%a7%e8%a4%87%e6%95%b0%e9%99%a4%e5%a4%96%e3%81%a7%e3%81%8d%e3%81%aa%e3%81%84/#post-188182)
 * odmodmさん
    そういうわけでバージョン 4.4.1-alpha-36006 に入りましたの。フォーラム
   へ書き込んでいただいたことが、新しいことに挑戦する良いきっかけになりました。ありがとう
   ございました。
 * Hinaloeさん、テストコードありがとうございました！

15件の返信を表示中 - 1 - 15件目 (全16件中)

1 [2](https://ja.wordpress.org/support/topic/wp_list_categories%e3%81%ae%e3%83%91%e3%83%a9%e3%83%a1%e3%83%bc%e3%82%bfexclude_tree%e3%81%a7%e8%a4%87%e6%95%b0%e9%99%a4%e5%a4%96%e3%81%a7%e3%81%8d%e3%81%aa%e3%81%84/page/2/?output_format=md)
[→](https://ja.wordpress.org/support/topic/wp_list_categories%e3%81%ae%e3%83%91%e3%83%a9%e3%83%a1%e3%83%bc%e3%82%bfexclude_tree%e3%81%a7%e8%a4%87%e6%95%b0%e9%99%a4%e5%a4%96%e3%81%a7%e3%81%8d%e3%81%aa%e3%81%84/page/2/?output_format=md)

 トピック「wp_list_categories()のパラメータexclude_treeで複数除外できない」には新た
に返信することはできません。

 * フォーラム: [バグ報告と提案](https://ja.wordpress.org/support/forum/feedback/)
 * 16件の返信
 * 4人の参加者
 * 最後の返信者: [odmodm](https://ja.wordpress.org/support/users/odmodm/)
 * 最後の活動: [10年、 10ヶ月前](https://ja.wordpress.org/support/topic/wp_list_categories%e3%81%ae%e3%83%91%e3%83%a9%e3%83%a1%e3%83%bc%e3%82%bfexclude_tree%e3%81%a7%e8%a4%87%e6%95%b0%e9%99%a4%e5%a4%96%e3%81%a7%e3%81%8d%e3%81%aa%e3%81%84/page/2/#post-188183)
 * 状態: 解決済

## トピック

### 人気のトピック

### 返信がないトピック

### サポート関連ではないトピック

### 解決済みのトピック

### 未解決のトピック

### すべてのトピック
