1

我在网站上拥有的一种自定义帖子类型现在不再有效:数据库条目仍然存在,但我无法访问这些帖子。我认为这是已知的永久链接问题,但是经过大量帖子并尝试了所提供的解决方案,我仍然遇到了这个问题。

我有一个带有一些排序代码的“single,php”文件,然后重定向到三个不同的单个文件(“single-author.php”、“single-book.php”、“single-event.php”)。

我尝试过的事情:

  • 切换永久链接结构并切换回
  • 刷新重写规则
  • 检查 .htaccess 中的重写规则

如果我在这个自定义帖子类型中创建一个新条目,我可以在“预览”中看到它,但是一旦我发布它,我就会得到 404。这个问题似乎不会影响我在网站上运行的其他自定义帖子类型. 除了最近的 WP 更新,我没有对网站进行任何更改。

我在下面附上了相关代码 - 任何指针或帮助将不胜感激,因为我不确定要尝试什么其他方法来解决问题。

非常感谢!

add_action('init', 'authors_register');

function authors_register() {

$labels = array(
    'name' => _x('Authors', 'post type general name'),
    'singular_name' => _x('Author', 'post type singular name'),
    'add_new' => _x('Add New', 'portfolio item'),
    'add_new_item' => __('Add New Author'),
    'edit_item' => __('Edit Author'),
    'new_item' => __('New Author'),
    'view_item' => __('View Author'),
    'search_items' => __('Search Authors'),
    'not_found' =>  __('Nothing found'),
    'not_found_in_trash' => __('Nothing found in Trash'),
    'parent_item_colon' => ''
);

$args = array(
    'labels' => $labels,
    'public' => true,
    'publicly_queryable' => true,
    'show_ui' => true,
    'query_var' => true,
    'rewrite' => true,
    'capability_type' => 'post',
    'hierarchical' => false,
    'menu_position' => 5,
    'supports' => array('title','thumbnail','revisions','excerpt'),
    'taxonomies' => array('category', 'post_tag')
  ); 

register_post_type( 'author' , $args ); 

}

single.php 中的排序/切换代码:

<?php if ('post_type=book') { include (TEMPLATEPATH . '/single-book.php'); } 

elseif ('post_type=event') { include (TEMPLATEPATH . '/single-event.php'); } 

elseif ('post_type=author') { include (TEMPLATEPATH . '/single-author.php'); } 

else { include (TEMPLATEPATH . '/single-post.php'); } ?>
4

1 回答 1

0
<?php if ('post_type=book') { include (TEMPLATEPATH . '/single-book.php'); } 

elseif ('post_type=event') { include (TEMPLATEPATH . '/single-event.php'); } 

elseif ('post_type=author') { include (TEMPLATEPATH . '/single-author.php'); } 

else { include (TEMPLATEPATH . '/single-post.php'); } ?>

Will always return single-book.php

'post_type=books' will always return true. You must have the post_type in a variable and check for each

<?php 
$post_type =  get_post_type();

if ( $post_type == 'book') { include (TEMPLATEPATH . '/single-book.php'); } 
elseif ($post_type == 'event') { include (TEMPLATEPATH . '/single-event.php'); } 
elseif ($post_type == 'author') { include (TEMPLATEPATH . '/single-author.php'); } 
else { include (TEMPLATEPATH . '/single-post.php'); } ?>

Also, author is not a reserved post type. The reserved post types are:

post
page
attachment
revision
nav_menu_item
于 2013-10-28T15:39:52.937 回答