具有自定义分类法的自定义帖子类型的单页无效

时间:2018-12-19 15:24:22

标签: wordpress permalinks

我使用自定义分类法创建了自定义帖子类型“推荐” 它在除单页页面外均有效,当我单击永久链接时显示“未找到”。

这是我的自定义帖子类型/分类法代码:

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管理面板中的永久链接,但该链接仍无法正常工作

对于自定义帖子类型“ testimonials”,我在子主题中创建了single-testimonials.php

非常感谢您的帮助!

2 个答案:

答案 0 :(得分:0)

每次尝试后,您都可以尝试创建taxonomy-subjects.php和refresh your permalinks

答案 1 :(得分:0)

要修复我的错误,我必须将'publicly_queryable'设置为'true' 现在就可以使用))