wordpress - 带有自定义分类的自定义帖子类型的单页不起作用
问题描述
我使用自定义分类创建了自定义帖子类型“推荐”,除了单页外,它运行良好,当我单击永久链接时,它显示“未找到”。
这是我的自定义帖子类型/分类法的代码:
function testimonials_custom_post_type()
{
$labels = array(
'name' => _x('Testimonials', 'Post type general name'),
'singular_name' => _x('Testimonial', 'Post type singular name'),
'add_new' => _x('Add new Testimonial', 'Grower'),
'add_new_item' => __('Add new Testimonial'),
'edit_item' => __('Edit Testimonial'),
'new_item' => __('New Testimonial'),
'all_items' => __('All Testimonials'),
'view_item' => __('View Testimonial'),
'search_items' => __('Search Testimonials'),
'not_found' => __('No testimonials found'),
'not_found_in_trash' => __('No testimonials found in Trash'),
'parent_item_colon' => '',
);
$args = array(
'labels' => $labels,
'public' => true,
'publicly_queryable' => false,
'query_var' => false,
'rewrite' => true,
'capability_type' => 'post',
'has_archive' => false,
'hierarchical' => false,
'exclude_from_search' => false,
'supports' => array('title', 'editor', 'thumbnail' ),
'menu_position' => 6,
'menu_icon' => 'dashicons-id',
'taxonomies' => array( 'subjects' ),
);
register_post_type('testimonials', $args);
}
add_action('init', 'testimonials_custom_post_type');
/*register custom taxonomies for testimonials*/
add_action( 'init', 'create_testimonials_taxonomies', 0 );
function create_testimonials_taxonomies() {
// Add new taxonomy, make it hierarchical (like categories)
$labels = array(
'name' => _x( 'Subjects', 'subjects', 'textdomain' ),
'singular_name' => _x( 'Subject', 'subject', 'textdomain' ),
'search_items' => __( 'Search Subject', 'textdomain' ),
'all_items' => __( 'All Subjects', 'textdomain' ),
'edit_item' => __( 'Edit Subject', 'textdomain' ),
'update_item' => __( 'Update Subject', 'textdomain' ),
'add_new_item' => __( 'Add new Subject', 'textdomain' ),
'new_item_name' => __( 'New Category Subject', 'textdomain' ),
'menu_name' => __( 'Subject', 'textdomain' ),
);
$args = array(
'hierarchical' => true,
'labels' => $labels,
'show_ui' => true,
'show_admin_column' => false,
'query_var' => true,
'rewrite' => array( 'slug' => 'subjects' ),
);
register_taxonomy( 'subjects', array( 'testimonials' ), $args );
}
/*register custom taxonomies for testimonials*/
我尝试使用flush_rewrite_rules( false ); 并尝试在 wp 管理面板中更新永久链接它仍然无法正常工作
对于自定义帖子类型“推荐”,我在我的子主题中创建了 single-testimonials.php
非常感谢您的帮助!
解决方案
为了修复我的错误,我必须将“publicly_queryable”设置为“true”,它现在可以工作了))
推荐阅读
- c# - C# WebHttpRequest 如何添加多个标头?
- google-chrome - Chrome 扩展开发 - 使用自 chrome 版本 88 以来不推荐使用的自签名证书标志访问 localhost https,还有什么替代方案?
- html - 不要在 Angular html 模板中捕获错误
- flutter - 如何在 Flutter 中使用 Agora 实现 Callkeep?
- angular - 打开角度材质对话框时启用主页滚动
- ruby - Ruby on rails,如何比较两个哈希值?
- php - 将字符串分成两部分:第一部分是标题,第二部分是使用 php 的章节
- haskell - (Haskell)无法理解错误:没有使用 '' 引起的(Ord a)实例
- node.js - Node.js:如何从一个字符串和另一个数组创建一个数组?
- php - 生成具有给定约束的给定数量的随机数(PHP)?