自定义帖子类型页面404

时间:2014-03-13 04:22:17

标签: php wordpress custom-post-type

我有自定义帖子类型的声明:

$labels = array(
       'name' => _x('Partners', 'post type general name'),
       'singular_name' => _x('Partner', 'post type singular name'),
       'add_new' => _x('Add New', 'book'),
       'add_new_item' => __('Add New Partner'),
       'edit_item' => __('Edit Partner'),
       'new_item' => __('New Partner'),
       'all_items' => __('All Partner'),
       'view_item' => __('View Partner'),
       'search_items' => __('Search Partner'),
       'not_found' => __('No Partner found'),
       'not_found_in_trash' => __('No Partner found in the Trash'),
       'parent_item_colon' => '',
       'menu_name' => 'Partners'
   );
   $args = array(
       'labels' => $labels,
       'description' => 'Holds our Partners and Partner specific data',
       'public' => true,
       'menu_position' => 5,
       'supports' => array('title', 'editor', 'thumbnail', 'excerpt'),
       'has_archive' => true,
       'menu_icon' => 'dashicons-groups',
       'public' => true,
       'show_ui' => true, // UI in admin panel
       'capability_type' => 'post',
       'hierarchical' => true,
       'rewrite' => array('slug' => 'partners'),
       'has_archive' => true,
   );
   register_post_type('partners', $args)

但是当我查询我的自定义帖子类型时,即使我已经创建了我的单一{custom-post-type} .php,它也会引发Page not not found错误。当我输入创建的帖子的网址时,它不显示帖子,我也有自定义帖子类型的自定义分类

$labels = array(
       'name' => _x('Partners Category', 'taxonomy general name'),
       'singular_name' => _x('Partner Category', 'taxonomy singular name'),
       'search_items' => __('Search Partner Categories'),
       'all_items' => __('All Partner Categories'),
       'parent_item' => __('Parent Partner Category'),
       'parent_item_colon' => __('Parent Partner Category:'),
       'edit_item' => __('Edit Partner Category'),
       'update_item' => __('Update Partner Category'),
       'add_new_item' => __('Add New Partner Category'),
       'new_item_name' => __('New Partner Category'),
       'menu_name' => __('Partners Categories'),
   );
   $args = array(
       'hierarchical' => true,
       'labels' => $labels,
       'show_ui' => true,
       'query_var' => true,
       'rewrite' => array('hierarchical' => true, 'with_front' => false, 'slug' => 'partners')
   );
   register_taxonomy('partners_category', 'partners', $args);

任何人都能解释一下吗?

1 个答案:

答案 0 :(得分:0)

我找到了测试解决方案:

register_post_type('partners', $args)

TO ';'

 register_post_type('partners', $args);
  

在此值之后添加:“flush_rewrite_rules();”

register_post_type('partners', $args);
flush_rewrite_rules();


register_taxonomy('partners_category', 'partners', $args);
flush_rewrite_rules();

enter image description here

taxonomy-partners.php 
archive-partners.php
single-partners.php 
taxonomy-partners-tag.php