サポート » プラグイン » カスタム投稿の個別記事が404エラーになる

  • fanction.phpに下記の内容を書き、カスタム投稿を作成しました。

    add_action( ‘init’, ‘create_post_type’ );
    function create_post_type() {
    register_post_type(‘test’,
    array(
    ‘label’ => ‘エリア別’,
    ‘description’ => ”,
    ‘public’ => true,
    ‘show_ui’ => true,
    ‘show_in_menu’ => true,
    ‘capability_type’ => ‘post’,
    ‘hierarchical’ => false,
    ‘rewrite’ => true,
    ‘query_var’ => false,
    ‘has_archive’ => true,
    ‘exclude_from_search’ => false,
    ‘menu_position’ => 20,
    ‘supports’ => array(‘title’,’editor’,’thumbnail’),
    ‘taxonomies’ => array(‘test_cat’),
    ‘labels’ => array (
    ‘name’ => ‘投稿一覧’,
    ‘singular_name’ => ‘投稿登録’,
    ‘add_new_test’ => ‘新しい投稿を追加する’,
    ‘add_new’ => ‘新しい投稿を追加する’,
    ‘edit_test’ => ‘投稿内容を編集’
    )
    )
    );

    register_taxonomy(
    ‘test_cat’,
    ‘test’,
    array(
    ‘hierarchical’ => true,
    ‘label’ => ‘カテゴリー’,
    ‘show_ui’ => true,
    ‘query_var’ => true,
    ‘rewrite’ => array(‘slug’ => ‘test’),
    ‘singular_label’ => ‘カテゴリー’
    )
    );

    カスタム投稿のパーマリンクには「Custom Post Type Permalinks」を使用して
    ドメイン/test/%test_cat%/%post_id%/ としています。
    taxonomy.phpは問題なく表示しますが、個別記事(single-test.php)は404エラーになってしまいます。

    wordpressのバージョン 4.5.3
    Custom Post Type Permalinksのバージョン 2.1.1
    カスタムフィールドテンプレートのバージョン 2.3.6

    どなたかご教授いただけないでしょうか。

    • このトピックはark_1125が7年、 8ヶ月前に変更しました。
8件の返信を表示中 - 1 - 8件目 (全8件中)
  • Honda

    (@rocketmartue)

    register_post_typequery_vartrueにしてみてください。

    トピック投稿者 ark_1125

    (@ark_1125)

    ご回答有難うございます。

    ‘query_var’ => true,に変更してパーマリンクも空更新してみましたが、
    ページが見つかりませんと表示されます…。
    その他に確認すべき点はありますでしょうか。

    Honda

    (@rocketmartue)

    カスタム投稿のパーマリンクには「Custom Post Type Permalinks」を使用して
    ドメイン/test/%test_cat%/%post_id%/ としています。

    %test_cat%としているのにregister_taxonomyの slug を test にリライトしていますが、
    register_taxonomyの部分を

    $args = array(
    	"hierarchical"      => true,
    	"label"             => "カテゴリー",
    	"show_ui"           => true,
    	"query_var"         => true,
    	"rewrite"           => array( 'slug' => 'test_cat' ),
    	"show_admin_column" => true,
    );
    register_taxonomy( "test_cat", array( "test" ), $args );

    に変更するとどうなりますか?

    トピック投稿者 ark_1125

    (@ark_1125)

    下記のように変更してみました。

    add_action( ‘init’, ‘create_post_type’ );
    function create_post_type() {
    register_post_type(‘test’,
    array(
    ‘label’ => ‘エリア別’,
    ‘description’ => ”,
    ‘public’ => true,
    ‘show_ui’ => true,
    ‘show_in_menu’ => true,
    ‘capability_type’ => ‘post’,
    ‘hierarchical’ => false,
    ‘rewrite’ => true,
    ‘query_var’ => true,
    ‘has_archive’ => true,
    ‘exclude_from_search’ => false,
    ‘menu_position’ => 20,
    ‘supports’ => array(‘title’,’editor’,’thumbnail’),
    ‘taxonomies’ => array(‘test_cat’),
    ‘labels’ => array (
    ‘name’ => ‘投稿一覧’,
    ‘singular_name’ => ‘投稿登録’,
    ‘add_new_item’ => ‘新しい投稿を追加する’,
    ‘add_new’ => ‘新しい投稿を追加する’,
    ‘edit_item’ => ‘投稿内容を編集’
    )
    )
    );

    $args = array(
    “hierarchical” => true,
    “label” => “カテゴリー”,
    “show_ui” => true,
    “query_var” => true,
    “rewrite” => array( ‘slug’ => ‘test_cat’ ),
    “show_admin_column” => true,
    );
    register_taxonomy( “test_cat”, array( “test” ), $args );

    すると、http://ドメイン/test/%test_cat% 、http://ドメイン/test/%test_cat%/%post_id%/
    両方エラーになってしまいました…。

    Honda

    (@rocketmartue)

    シングルクォート、ダブルクォートは、どちらも半角にしていますか?
    ‘’ではなくて''
    “”ではなくて""
    貼り付けてあるコードは、どちらも全角のようです。

    それから、閉じかっこ}も抜けています。

    トピック投稿者 ark_1125

    (@ark_1125)

    ご指摘いただいた点、すべて全角になっておりました。動作も問題ありません。
    何度もアドバイスをいただき有難うございました。

    トピック投稿者 ark_1125

    (@ark_1125)

    何度もすみません、記事個別ページは、http://ドメイン/test/%test_cat%/%post_id%/
    で表示されるようになったのですが、 http://ドメイン/test/%test_cat%/(taxonomy.php)が
    「ページが見つかりません」という表示になってしまいました。

    現在のfanction.phpはこのようになっています。

    /* カスタム投稿タイプ */
    add_action( ‘init’, ‘create_post_type’ );
    function create_post_type() {
    register_post_type(‘test’,
    array(
    ‘label’ => ‘エリア別’,
    ‘description’ => ”,
    ‘public’ => true,
    ‘show_ui’ => true,
    ‘show_in_menu’ => true,
    ‘capability_type’ => ‘post’,
    ‘hierarchical’ => false,
    ‘rewrite’ => true,
    ‘query_var’ => true,
    ‘has_archive’ => true,
    ‘exclude_from_search’ => false,
    ‘menu_position’ => 20,
    ‘supports’ => array(‘title’,’editor’,’thumbnail’),
    ‘taxonomies’ => array(‘test_cat’),
    ‘labels’ => array (
    ‘name’ => ‘投稿一覧’,
    ‘singular_name’ => ‘投稿登録’,
    ‘add_new_item’ => ‘新しい投稿を追加する’,
    ‘add_new’ => ‘新しい投稿を追加する’,
    ‘edit_item’ => ‘投稿内容を編集’
    )
    )
    );

    $args = array(
    ‘hierarchical’ => true,
    ‘label’ => ‘カテゴリー’,
    ‘show_ui’ => true,
    ‘query_var’ => true,
    ‘rewrite’ => array( ‘slug’ => ‘test_cat’ ),
    ‘show_admin_column’ => true,
    );
    register_taxonomy( ‘test_cat’, array( ‘test’ ), $args );
    }

    何か変更すべき点はありますでしょうか…。

    Honda

    (@rocketmartue)

    http://ドメイン/test/%test_cat%/(taxonomy.php)が
    「ページが見つかりません」という表示になってしまいました。

    設定 > パーマリンク設定 で、一度「変更を保存」ボタンをクリックしてみてください。
    これで、改善される場合があります。

    管理画面 > エリア別 > カテゴリー で、カテゴリーは登録されていますか?
    登録されているのであれば、カテゴリー名の上にマウスをのせると表示されるリンクから、「表示」をクリックした場合ページは表示されますか?
    その時のURLは、http://ドメイン/test/%test_cat%/と違うと思うので確認してみてください。

8件の返信を表示中 - 1 - 8件目 (全8件中)
  • トピック「カスタム投稿の個別記事が404エラーになる」には新たに返信することはできません。