Title: 複数のカスタム投稿タイプで1つのカスタム分類を用いた際のテンプレート
Last modified: 2016年7月30日

---

# 複数のカスタム投稿タイプで1つのカスタム分類を用いた際のテンプレート

 *  [sola](https://ja.wordpress.org/support/users/solatc/)
 * (@solatc)
 * [11年、 8ヶ月前](https://ja.wordpress.org/support/topic/%e8%a4%87%e6%95%b0%e3%81%ae%e3%82%ab%e3%82%b9%e3%82%bf%e3%83%a0%e6%8a%95%e7%a8%bf%e3%82%bf%e3%82%a4%e3%83%97%e3%81%a71%e3%81%a4%e3%81%ae%e3%82%ab%e3%82%b9%e3%82%bf%e3%83%a0%e5%88%86%e9%a1%9e%e3%82%92/)
 * 複数のカスタム投稿タイプにて1つのカスタム分類を用いる場合、
    “[http://www.example.com/posttypeA/taxonomy/term/&#8221](http://www.example.com/posttypeA/taxonomy/term/&#8221);“
   [http://www.example.com/posttypeB/taxonomy/term/&#8221](http://www.example.com/posttypeB/taxonomy/term/&#8221);
   上記のような複数のカスタム投稿タイプアーカイブテンプレート内のループで、”posttypeA”
   と”posttypeB”が混在したループが生成されてしまいます。 “[http://www.example.com/posttypeA/taxonomy/term/&#8221](http://www.example.com/posttypeA/taxonomy/term/&#8221);
   上記のアーカイブページでは”posttypeA”の投稿が。 “[http://www.example.com/posttypeB/taxonomy/term/&#8221](http://www.example.com/posttypeB/taxonomy/term/&#8221);
   上記のアーカイブページでは”posttypeB”の投稿がそれぞれ表示されるよう、 現在は以下
   の様な、若干いびつなコードを書いて対処しています。
 * > `<?php
   >  /* HTML出力前 */ $request_uri = $_SERVER[‘REQUEST_URI’]; // “/posttype/
   > taxonomy/term/” ?>`
 * > `
   >  <?php /* ループ前 */ $uriDirectoryArray = explode( “/” , $request_uri );
   > if( is_array( $uriDirectoryArray ) ){ query_posts( array( ‘post_type’ => $uriDirectoryArray[
   > 1], // “posttypeA” か “posttypeB” ‘tax_query’ => array( array( ‘taxonomy’ =
   > > ‘region’, ‘terms’ => $uriDirectoryArray[3], ‘field’ => ‘slug’ ) ), ‘posts_per_page’
   > => 10 ) ); } ?> `
 * よりスマートに指定出来ないものでしょうか？
    よろしくお願いします。

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

 *  [gblsm](https://ja.wordpress.org/support/users/gblsm/)
 * (@gblsm)
 * [11年、 8ヶ月前](https://ja.wordpress.org/support/topic/%e8%a4%87%e6%95%b0%e3%81%ae%e3%82%ab%e3%82%b9%e3%82%bf%e3%83%a0%e6%8a%95%e7%a8%bf%e3%82%bf%e3%82%a4%e3%83%97%e3%81%a71%e3%81%a4%e3%81%ae%e3%82%ab%e3%82%b9%e3%82%bf%e3%83%a0%e5%88%86%e9%a1%9e%e3%82%92/#post-203023)
 * 混在したループが生成されるのは、どのテンプレートで表示したときですか？
    archive-
   カスタム投稿タイプのスラッグ.php taxonomy-タクソノミー-ターム.php taxonomy-タクソノミー.
   php taxonomy.php archive.php
 *  トピック投稿者 [sola](https://ja.wordpress.org/support/users/solatc/)
 * (@solatc)
 * [11年、 8ヶ月前](https://ja.wordpress.org/support/topic/%e8%a4%87%e6%95%b0%e3%81%ae%e3%82%ab%e3%82%b9%e3%82%bf%e3%83%a0%e6%8a%95%e7%a8%bf%e3%82%bf%e3%82%a4%e3%83%97%e3%81%a71%e3%81%a4%e3%81%ae%e3%82%ab%e3%82%b9%e3%82%bf%e3%83%a0%e5%88%86%e9%a1%9e%e3%82%92/#post-203026)
 * gblsm 様
 * メッセージありがとうございます。
 * > taxonomy-タクソノミー.php
    > taxonomy.php
 * 上記で確認済みです。
    恐らく、ご提示いただいた他の2つのテンプレートでも混在する
   だろうと思います。
 *  [gblsm](https://ja.wordpress.org/support/users/gblsm/)
 * (@gblsm)
 * [11年、 8ヶ月前](https://ja.wordpress.org/support/topic/%e8%a4%87%e6%95%b0%e3%81%ae%e3%82%ab%e3%82%b9%e3%82%bf%e3%83%a0%e6%8a%95%e7%a8%bf%e3%82%bf%e3%82%a4%e3%83%97%e3%81%a71%e3%81%a4%e3%81%ae%e3%82%ab%e3%82%b9%e3%82%bf%e3%83%a0%e5%88%86%e9%a1%9e%e3%82%92/#post-203031)
 * 試しにプラグインを使ってカスタム投稿タイプとカスタムタクソノミーを作り、solaさん
   の状況が再現しました。
 * プラグイン Custom Post Type UI を使って：
    /ptA ⇒ 投稿タイプ ptA のアーカイブ/
   ptB ⇒ 投稿タイプ ptB のアーカイブ /taxC/termD ⇒ タクソノミー taxC のターム termD
   のアーカイブ
 * プラグイン Custom Post Type Permalinks を使って：
    /ptA/taxC/termD ⇒ ptA と ptB
   が混在したアーカイブが表示される。
 * しかし /ptA?taxC=termD や /ptB?taxC=termD だと混在せず表示されるので、Custom 
   Post Type Permalinks によるパーマリンクのリライトがうまく働いていないみたいです。
 * もし、このプラグインをお使いでしたら作者さんに連絡をとってみてはどうでしょう。
   一年前に下記のようなバグ報告があったので関係しているかもしれません。
    [[resolved] Archive taxomomies with many CPT](https://wordpress.org/support/topic/archive-taxomomies-with-many-cpt)
 *  トピック投稿者 [sola](https://ja.wordpress.org/support/users/solatc/)
 * (@solatc)
 * [11年、 8ヶ月前](https://ja.wordpress.org/support/topic/%e8%a4%87%e6%95%b0%e3%81%ae%e3%82%ab%e3%82%b9%e3%82%bf%e3%83%a0%e6%8a%95%e7%a8%bf%e3%82%bf%e3%82%a4%e3%83%97%e3%81%a71%e3%81%a4%e3%81%ae%e3%82%ab%e3%82%b9%e3%82%bf%e3%83%a0%e5%88%86%e9%a1%9e%e3%82%92/#post-203037)
 * gblsm 様
 * 引き続きメッセージありがとうございます。
 * > Custom Post Type Permalinks によるパーマリンクのリライトがうまく働いていない
   みたいです。
    プラグインのバグだったのですね。 確かに「Custom Post Type Permalinks」
   を用いております。 全く気付きませんでした。
 * 「Custom Post Type Permalinks」を用いず、上手くリライト出来れば良いのですが、
   この際勉強してみようと思います。
 * ありがとうございます。
 *  [gblsm](https://ja.wordpress.org/support/users/gblsm/)
 * (@gblsm)
 * [11年、 8ヶ月前](https://ja.wordpress.org/support/topic/%e8%a4%87%e6%95%b0%e3%81%ae%e3%82%ab%e3%82%b9%e3%82%bf%e3%83%a0%e6%8a%95%e7%a8%bf%e3%82%bf%e3%82%a4%e3%83%97%e3%81%a71%e3%81%a4%e3%81%ae%e3%82%ab%e3%82%b9%e3%82%bf%e3%83%a0%e5%88%86%e9%a1%9e%e3%82%92/#post-203038)
 * プラグインの修正方法を別のトピックに書きました。リライトルールの参考にもなると
   思います。
    [https://ja.forums.wordpress.org/topic/148586](https://ja.forums.wordpress.org/topic/148586)
 * 作者さんからコメントが貰えるとよいのですが。
 *  [Toro_Unit (Hiroshi Urabe)](https://ja.wordpress.org/support/users/toro_unit/)
 * (@toro_unit)
 * [11年、 7ヶ月前](https://ja.wordpress.org/support/topic/%e8%a4%87%e6%95%b0%e3%81%ae%e3%82%ab%e3%82%b9%e3%82%bf%e3%83%a0%e6%8a%95%e7%a8%bf%e3%82%bf%e3%82%a4%e3%83%97%e3%81%a71%e3%81%a4%e3%81%ae%e3%82%ab%e3%82%b9%e3%82%bf%e3%83%a0%e5%88%86%e9%a1%9e%e3%82%92/#post-203249)
 * プラグイン作者です。
    今更ですが、この問題についてですが、タクソノミーのリンク
   周りはあんまり複雑なコトが出来ません。get_term_link等で、
    - リンクを生成する場合、複数のpost_typeに紐付いている場合に、どちらのモノか特定
      が出来ない
    - post_typeパラメーターを追加すると、タクソノミーテンプレートより、カスタム投稿
      タイプのテンプレートが先に読まれる
 * 等の問題が発生するので、URLの見た目だけ変更するという実装になっています。
    一応、
   1.0.0で、post_typeパラメーターを追加するかどうかの設定を足しました。
 * こちらで対処することが出来るかと思いますが、テンプレートの読み込みなど、かなり
   挙動が変更されてしまう部分がありますので、ご注意下さい。
 *  [gblsm](https://ja.wordpress.org/support/users/gblsm/)
 * (@gblsm)
 * [11年、 7ヶ月前](https://ja.wordpress.org/support/topic/%e8%a4%87%e6%95%b0%e3%81%ae%e3%82%ab%e3%82%b9%e3%82%bf%e3%83%a0%e6%8a%95%e7%a8%bf%e3%82%bf%e3%82%a4%e3%83%97%e3%81%a71%e3%81%a4%e3%81%ae%e3%82%ab%e3%82%b9%e3%82%bf%e3%83%a0%e5%88%86%e9%a1%9e%e3%82%92/#post-203254)
 * Toro_Unitさん、コメントありがとうございます。テンプレートの読み込み順も影響受け
   てしまうんですね。うまく働いていないみたい…なんて言ってしまい申し訳ありません
   でした。

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

 トピック「複数のカスタム投稿タイプで1つのカスタム分類を用いた際のテンプレート」
には新たに返信することはできません。

## タグ

 * [カスタム分類](https://ja.wordpress.org/support/topic-tag/%e3%82%ab%e3%82%b9%e3%82%bf%e3%83%a0%e5%88%86%e9%a1%9e/)
 * [カスタム投稿タイプ](https://ja.wordpress.org/support/topic-tag/%e3%82%ab%e3%82%b9%e3%82%bf%e3%83%a0%e6%8a%95%e7%a8%bf%e3%82%bf%e3%82%a4%e3%83%97/)

 * フォーラム: [テーマ](https://ja.wordpress.org/support/forum/themes/)
 * 7件の返信
 * 3人の参加者
 * 最後の返信者: [gblsm](https://ja.wordpress.org/support/users/gblsm/)
 * 最後の活動: [11年、 7ヶ月前](https://ja.wordpress.org/support/topic/%e8%a4%87%e6%95%b0%e3%81%ae%e3%82%ab%e3%82%b9%e3%82%bf%e3%83%a0%e6%8a%95%e7%a8%bf%e3%82%bf%e3%82%a4%e3%83%97%e3%81%a71%e3%81%a4%e3%81%ae%e3%82%ab%e3%82%b9%e3%82%bf%e3%83%a0%e5%88%86%e9%a1%9e%e3%82%92/#post-203254)
 * 状態: 未解決

## トピック

### 人気のトピック

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

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

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

### 未解決のトピック

### すべてのトピック
