カスタム投稿のみ404エラーが効かない。
-
カスタム投稿タイプの記事階層のみ404エラー(404.php)が効かず、
なぜかindex.phpが表示されてしまい困っております。その他のページはすべて上手く404エラー(404.php)が返されます。
どのような原因が考えられますでしょうか?ご教示いただけますと幸いです。
【現象例】
(例1)
http://www.サイトURL/適当な文字列
→正常に404エラー表示(例2)
http://www.サイトURL/project/記事ID/適当な文字列
→正常に404エラー表示(例3)
http://www.サイトURL/project/記事ID
→正常に記事IDのページが表示される(single-projects.php)。(例4)
http://www.サイトURL/project/記事ID適当な文字列
→404エラー作動せず記事IDのページが表示される。(例5)
http://www.サイトURL/project/適当な文字列
→404エラー作動せずなぜかindex.phpが読み込まれるfunctions.phpに下記のようなソースコードを記入しカスタム投稿を作っています。
↓↓
—————————-
// カスタム投稿()
function codex_custom_init() {
$labels = array(
‘name’ => ‘projects’,
‘singular_name’ => ‘projects’,
‘add_new’ => ‘Add New’,
‘add_new_item’ => ‘Add New projects’,
‘edit_item’ => ‘Edit projects’,
‘new_item’ => ‘New projects’,
‘all_items’ => ‘All projects’,
‘view_item’ => ‘View projects’,
‘search_items’ => ‘Search projects’,
‘not_found’ => ‘No projects found’,
‘not_found_in_trash’ => ‘No projects found in Trash’,
‘parent_item_colon’ => ”,
‘menu_name’ => ‘projects’
);$args = array(
‘label’ => “事例紹介”,
‘public’ => true,
‘publicly_queryable’ => true,
‘show_ui’ => true,
‘show_in_menu’ => true,
‘query_var’ => true,
‘rewrite’ => array( ‘slug’ => ‘projects’ ),
‘capability_type’ => ‘post’,
‘has_archive’ => false,
‘hierarchical’ => false,
‘menu_position’ => null,
// フィールド削除’supports’ => array(‘title’,’editor’,’author’,’thumbnail’,’excerpt’,’comments’)
‘supports’ => array(‘title’,’editor’,’thumbnail’,’custom-fields’,’excerpt’,’author’,’trackbacks’,’comments’,’revisions’,’page-attributes’));
$attachment_id = get_field(‘projects_gallery’);
$size = “full”;
$image = wp_get_attachment_image_src( $attachment_id, $size );
$attachment = get_post( get_field(‘projects_gallery’) );
$alt = get_post_meta($attachment->ID, ‘_wp_attachment_image_alt’, true);
$image_title = $attachment->post_title;register_post_type( ‘projects’, $args );
}
add_action( ‘init’, ‘codex_custom_init’ );//カスタム投稿(projects)のパーマリンク設定
add_action(‘init’, ‘myposttype_rewrite’);
function myposttype_rewrite() {
global $wp_rewrite;
$queryarg = ‘post_type=projects&p=’;
$wp_rewrite->add_rewrite_tag(‘%projects_id%’, ‘([^/]+)’,$queryarg);
$wp_rewrite->add_permastruct(‘projects’,’/project/%projects_id%’, false);
}
add_filter(‘post_type_link’, ‘myposttype_permalink’, 1, 3);
function myposttype_permalink($post_link, $id = 0, $leavename) {
global $wp_rewrite;
$post = &get_post($id);
if ( is_wp_error( $post ))
return $post;
$newlink = $wp_rewrite->get_extra_permastruct($post->post_type);
$newlink = str_replace(‘%’.$post->post_type.’_id%’, $post->ID, $newlink);
$newlink = home_url(user_trailingslashit($newlink));
return $newlink;
}
—————————-
- トピック「カスタム投稿のみ404エラーが効かない。」には新たに返信することはできません。