我创建了一个自定义帖子类型,其中'has_archive'为'false',以便能够创建一个与自定义帖子类型相同的slug页面:'Test'。
我想为“测试”页面创建子页面/子页面,但是我收到错误404页面。
有一种方法可以优先处理自定义帖子类型的网页吗?
add_action( 'init', 'cptui_register_my_cpts_test' );
function cptui_register_my_cpts_test() {
$labels = array(
"name" => __( 'Test', 'test' ),
"singular_name" => __( 'Test', 'test' ),
);
$args = array(
"label" => __( 'Test', 'test' ),
"labels" => $labels,
"description" => "",
"public" => true,
"publicly_queryable" => true,
"show_ui" => true,
"show_in_rest" => false,
"rest_base" => "",
"has_archive" => false,
"show_in_menu" => true,
"exclude_from_search" => false,
"capability_type" => "post",
"map_meta_cap" => true,
"hierarchical" => true,
"rewrite" => array( 'slug' => 'test'),
"query_var" => true,
"supports" => array( "title", "editor", "thumbnail" ),
);
register_post_type( "test", $args );
}
答案 0 :(得分:1)
function custom_rada_type() {
$labels = array(
'name' => 'Porady',
'singular_name' => 'Porady',
'menu_name' => 'Porady',
'parent_item_colon' => 'Kategoria rodzica',
'all_items' => 'Wszystkie porady',
'view_item' => 'Wyświetl poradę',
'add_new_item' => 'Dodaj poradę',
'add_new' => 'Dodaj poradę',
'edit_item' => 'Edytuj poradę',
'update_item' => 'Zaktualizuj poradę',
'search_items' => 'Wyszukaj poradę',
'not_found' => 'Nie znaleziono',
'not_found_in_trash' => 'Nie znaleziono w koszyku',
);
$args = array(
'label' => 'rada',
'description' => 'Szablony porad',
'labels' => $labels,
'supports' => array( 'title', 'editor', 'thumbnail', 'comments' ),
'taxonomies' => array( '' ),
'hierarchical' => false,
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'show_in_nav_menus' => true,
'show_in_admin_bar' => true,
'can_export' => true,
'has_archive' => 'porady',
'rewrite' => array( 'slug' => 'porady', 'with_front' => false ),
'exclude_from_search' => false,
'publicly_queryable' => true,
'capability_type' => 'post',
'menu_icon' => 'dashicons-editor-help',
);
register_post_type( 'rada', $args );
}
add_action( 'init', 'custom_rada_type', 0 );
add_action('init', function () {
add_rewrite_rule('porady/?$','index.php?pagename=porady', 'top');
flush_rewrite_rules();
}, 1000);