简体   繁体   English

自定义帖子类型页面404

[英]Custom post type page 404

I have a declaration of 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)

; ; but when i query my custom post type it throws a Page not found error even if i already created my single-{custom-post-type}.php. 但是,当我查询自定义帖子类型时,即使我已经创建了单个{custom-post-type} .php,它也会引发Page not found错误。 When i enter the url of the post created it doesnt show the post, i also have a custom taxonomy for that custom post type 当我输入创建的帖子的网址时,它不会显示该帖子,我也对该定制帖子类型有一个定制分类法

$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);

can anybody shed some light? 有人可以阐明吗?

I have find solution with testing: 我找到了测试解决方案:

register_post_type('partners', $args)

TO ';'

 register_post_type('partners', $args);

Add after this value: "flush_rewrite_rules();" 在此值之后添加:“ flush_rewrite_rules();”

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


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

在此处输入图片说明

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM