WordPressバージョン 5.2.3
PHP7.2.17
問題
WordPressでカスタム投稿の記事が404エラーになってしまう。
通常のブログ(投稿)に関しては、問題なく表示される。
カスタム投稿のアーカイブページには、記事タイトルやサムネイル、属するタームなどは取得でき、表示もできている。
カスタム投稿はfunctions.phpに記述して、プラグインなどでは作成していない。
以前は正しく表示されていたため、その頃のデータをインポートすると、カスタム投稿の記事が表示される。
しかし、何も変更せずにパーマリンク設定の『変更を保存』をクリックすると、またカスタム投稿の記事が404エラーになる。
パーマリンク設定に関することを変更したりすると、404エラーが出るので、そのあたりの問題だと思いますが、何か原因のわかる方はいらっしゃれば教えていただきたいです。
追記
パーマリンクを書き換えるプラグイン『Custom Post Type Permalinks』を使用しています。
カスタム投稿タイプはfunctions.phpに以下のように設定しています。
html
1add_action( 'init', 'create_post_type' ); 2function create_post_type() { 3 $Supports = [ 4 'title', 5 'editor', 6 'thumbnail', 7 'revisions' 8 ]; 9 10 register_post_type('activities', 11 array( 12 'label' => '活動', 13 'public' => true, 14 'show_ui' => true, 15 'show_in_menu' => true, 16 'capability_type' => 'post', 17 'rewrite' => array( 'slug' => 'activities'), 18 'hierarchical' => true, 19 'show_in_rest' => true, 20 'query_var' => false, 21 'has_archive' => true, 22 'exclude_from_search' => false, 23 'menu_position' => 5, 24 'supports' => $Supports 25 ) 26 ); 27 register_taxonomy( 28 'activities_cat', 29 'activities', 30 array( 31 'hierarchical' => true, 32 'label' => '活動カテゴリー', 33 'show_ui' => true, 34 'query_var' => true, 35 'show_in_rest' => true, 36 'rewrite' => array('slug' => 'activities'), 37 'singular_label' => '活動カテゴリー', 38 'show_admin_column' => true 39 ) 40 ); 41 register_post_type('works', 42 array( 43 'label' => '仕事', 44 'public' => true, 45 'show_ui' => true, 46 'show_in_menu' => true, 47 'capability_type' => 'post', 48 'rewrite' => array( 'slug' => 'works'), 49 'hierarchical' => true, 50 'show_in_rest' => true, 51 'query_var' => false, 52 'has_archive' => true, 53 'exclude_from_search' => false, 54 'menu_position' => 5, 55 'supports' => $Supports 56 ) 57 ); 58} 59add_rewrite_rule('activities/([^/]+)/page/([0-9]+)/?$', 'index.php?activities_cat=$matches[1]&paged=$matches[2]', 'top'); 60
あなたの回答
tips
プレビュー