###前提・実現したいこと
WordPressでサイトを構築しています。
カスタム投稿タイプを設定して、以下の様なURLにするのが理想です。
http://example.com/カスタム投稿タイプスラッグ/親ターム/子ターム/投稿名
階層はある程度増えたり減ったりします。
親だけのこともあれば、孫に及ぶこともあります。
下記のコードのように設定してみたのですが、期待通りのURLにはなるものの、404ページが表示されてしまいます。
子タームを設定せず、親(第一階層)までにすると、うまく表示されます。
http://example.com/カスタム投稿タイプスラッグ/親ターム/投稿名
###ソースコード
(1)functions.php
カスタム投稿タイプ名を「custom」とし、タクソノミーを「type」としています。
PHP
1add_rewrite_rule('custom/([^/]+)/page/([0-9]+)/?$', 'index.php?type=$matches[1]&paged=$matches[2]', 'top'); 2add_action( 'init', 'create_post_type' ); 3function create_post_type() { 4 register_post_type('custom', 5 array( 6 'label' => 'カスタム投稿', 7 'description' => '', 8 'public' => true, 9 'show_ui' => true, 10 'show_in_menu' => true, 11 'capability_type' => 'post', 12 'hierarchical' => false, 13 'rewrite' => true, 14 'query_var' => false, 15 'has_archive' => true, 16 'exclude_from_search' => false, 17 'menu_position' => 20, 18 'supports' => array('title','editor','revisions','page-attributes'), 19 'taxonomies' => array('type'), 20 'labels' => array ( 21 'name' => 'カスタム投稿', 22 'all_items' => 'カスタム投稿一覧' 23 ) 24 ) 25 ); 26 register_taxonomy( 27 'type', 28 'custom', 29 array( 30 'hierarchical' => true, 31 'label' => 'タクソノミー', 32 'show_ui' => true, 33 'query_var' => true, 34 'rewrite' => array('slug' => 'custom'), 35 'singular_label' => 'タクソノミー' 36 ) 37 ); 38}
(2)Custom Post Type Permalinks
http://example.com/custom/%type%/%postname%/
「カスタム分類のアーカイブのパーマリンクを変更する。」のチェックは外しました。
回りに相談できるひともおらず、良いお知恵を拝借できないものかと投稿させていただきます。
よろしくお願いします。
あなたの回答
tips
プレビュー