サポート » テーマ » カスタム投稿タイプの月別アーカイブで404になる

  • 解決済

    (@ai_da)


    カスタム投稿タイプをfunctionで設定し、
    月別アーカイブを確認しようと「http://◯◯/news(posttype)/2015/07/」にアクセスしたのですが、404が表示されてしまいます。

    現状の設定や把握している事を下記に羅列します。

    ・パーマリンク設定は/%postname%/を設定している。
    ・「http://◯◯/2015/07/?post_type=news」だと表示される
    ・functionsの記述

    function custom_post_types() {
        $label = 'ニュース&イベント';
        $slug = 'news';
        $option = array(
            'label' => $label,
            'labels' => array(
                'name' => $label,
                'singular_name' => $label,
                'add_new_item' => $label . 'を追加',
                'add_new' => '新規追加',
                'new_item' => '新規' . $label,
                'view_item' => $label . 'を表示',
                'not_found' => $label . 'は見つかりませんでした',
                'not_found_in_trash' => 'ゴミ箱に' . $label . 'はありません。',
                'search_items' => $label . 'を検索',
            ),
            'capability_type' => 'post',
            'menu_position' => 5,
            'rewrite' => array(
                'slug' => $slug,
                'with_front' => false
            ),
            'public' => true,
            'query_var' => true,
            'has_archive' => true,
            'hierarchical' => false,
            'supports' => array('title', 'editor'),
        );
        register_post_type('news', $option);
        flush_rewrite_rules(false);
    }
    add_action('init', 'custom_post_types');

    恐れ入りますが、ご教示頂ければ幸いです。
    よろしくお願いいたします。

1件の返信を表示中 - 1 - 1件目 (全1件中)
  • トピック投稿者

    (@ai_da)

    自己解決しました。
    プラグインで「Custom Post Type Permalinks」を使用していたのですが、
    1.0.0以上のバージョンで404になるというのが公式に記載されていました。

    http://www.torounit.com/blog/2015/04/13/1977/

    上記のコードから

    flush_rewrite_rules(false);

    を抜くだけで思っていた通りのURLに設定できました。

1件の返信を表示中 - 1 - 1件目 (全1件中)
  • トピック「カスタム投稿タイプの月別アーカイブで404になる」には新たに返信することはできません。