php - Wordpress:使用自定义帖子类型刷新永久链接
问题描述
我当前的层次结构如下:
- 自定义帖子类型:项目(projects.php)
- 单项目.php
我已经查看了这个链接:https : //wordpress.stackexchange.com/questions/202859/custom-post-type-pages-are-not-found,但是 flush_rewrite_rules(false); 似乎不起作用。我也尝试在永久链接页面上手动保存,但要么是 projects.php 能够出现,要么是 single-projects.php 出现,但不能同时出现。
来自https://getflywheel.com/layout/how-to-create-a-portfolio-for-your-wordpress-site/的 functions.php 中的代码:
//Creating Custom Post types for Projects
function setup_projects_cpt(){
$labels = array(
'name' => _x('Projects', 'post type general name'),
'singular_name' => _x('Project', 'post type singular name'),
'add_new' => _x('Add New', 'Project'),
'add_new_item' => __('Add New Project'),
'edit_item' => __('Edit Project'),
'new_item' => __('New Project'),
'all_items' => __('All Projects'),
'view_item' => __('View Project'),
'search_items' => __('Search Projects'),
'not_found' => __('No Projects Found'),
'not_found_in_trash' => __('No Projects found in the trash'),
'parent_item_colon' => '',
'menu_name' => 'Projects'
);
$args = array(
'labels' => $labels,
'description' => 'My Projects',
'rewrite' => array('slug' => 'projects'),
'public' => true,
'menu_position' => 5,
'supports' => array('title', 'editor', 'thumbnail', 'excerpt', 'custom-fields', 'page-attributes'),
'has_archive' => true,
'taxonomies' => array(''),
'menu_icon' => 'dashicons-admin-multisite', //Find the appropriate dashicon here: https://developer.wordpress.org/resource/dashicons/
);
register_post_type('projects', $args);
}
add_action('init', 'setup_projects_cpt');
//The following snippet is used to enable categories for the projects CPT.
function projects_taxonomy() {
register_taxonomy(
'project_categories', //The name of the taxonomy. Name should be in slug form (no spaces and all lowercase. no caps).
'projects', //post type name
array(
'hierarchical' => true,
'label' => 'Project Categories', //Label Displayed in the Admin when creating a new project
'query_var' => true,
'rewrite' => array(
'slug' => 'projects', // This controls the base slug that will display before each term
'with_front' => false // Don't display the category base before
)
)
);
}
add_action( 'init', 'projects_taxonomy');
add_theme_support( 'post-thumbnails', array( 'projects' ) ); // adds thumbnail support for the Projects CPT
解决方案
您对两个项目自定义帖子类型和项目类别使用相同的重写 slug,这就是它可能导致问题的原因
尝试改变任何你可能会得到解决的人
注意:更改后刷新重写规则
推荐阅读
- reactjs - 我应该将 access_token 存储在 localStorage+Redux 中还是 axios 默认值中?
- r - 如何根据另一个数据帧对一个数据帧执行操作?
- scala - 如何在 Spark 中使用 from_json() 数据框?
- woocommerce - 如何保存个人资料图片并在编辑帐户页面 woo-commerce 中显示
- arrays - 如何使用 ruby 从这个数组中获取所有元素?
- mongodb - 如何在 MONGODB 条件下使用 CASE 语句
- json - 根据golang中的条件执行自我解组方法或默认解组方法
- angular - 如何使用 CAS 针对 SpringBoot 后端授权 Angular5 应用程序
- javascript - 优化了色彩渲染功能
- javascript - JS/jQuery - 重新排列 HTML 表格元素