gpt4 book ai didi

php - WordPress - 自定义帖子类型单页上出现 404 错误

转载 作者:行者123 更新时间:2023-12-02 21:07:30 25 4
gpt4 key购买 nike

我使用自定义帖子类型,它也应该有自定义分类法。当我访问存档页面/kollektion/时,我可以看到此 CPT 的所有项目,当我访问/kollektion/mytaxonomy1/时,我可以看到分配给此分类的所有项目。

当我单击自定义帖子类型的单个项目时,出现 404 错误。我还尝试进入我的 WP 仪表板并再次更改并重新保存永久链接 - 但没有成功。

有人在我的声明中看到导致我的自定义帖子类型的单个页面出现 404 错误的错误吗?

谢谢。

functions.php:分类

// register two taxonomies to go with the post type
function sm_register_taxonomy() {
// set up labels
$labels = array(
'name' => 'Kollektionen Categories',
'singular_name' => 'Kollektion Category',
'search_items' => 'Search Kollektion Categories',
'all_items' => 'All Kollektion Categories',
'edit_item' => 'Edit Kollektion Category',
'update_item' => 'Update Kollektion Category',
'add_new_item' => 'Add New Kollektion Category',
'new_item_name' => 'New Kollektion Category',
'menu_name' => 'Kollektion Categories'
);
// register taxonomy
register_taxonomy( 'kollektionen', 'kollektion', array(
'hierarchical' => true,
'labels' => $labels,
'query_var' => true,
'show_admin_column' => true,
'rewrite' => array(
'slug' => 'kollektion', // This controls the base slug that will display before each term
'with_front' => false // Don't display the category base before
),
) );
}
add_action( 'init', 'sm_register_taxonomy' );

functions.php:自定义帖子类型

// Register Custom Post Type Kollektion
function post_type_kollektion() {

$labels = array(
'name' => _x( 'Kollektionen', 'Post Type General Name', 'genesis' ),
'singular_name' => _x( 'Kollektion', 'Post Type Singular Name', 'genesis' ),
'menu_name' => __( 'Kollektion', 'genesis' ),
'name_admin_bar' => __( 'Kollektion', 'genesis' ),
'parent_item_colon' => __( 'Parent Item:', 'genesis' ),
'all_items' => __( 'All Items', 'genesis' ),
'add_new_item' => __( 'Add New Item', 'genesis' ),
'add_new' => __( 'Add New', 'genesis' ),
'new_item' => __( 'New Item', 'genesis' ),
'edit_item' => __( 'Edit Item', 'genesis' ),
'update_item' => __( 'Update Item', 'genesis' ),
'view_item' => __( 'View Item', 'genesis' ),
'search_items' => __( 'Search Item', 'genesis' ),
'not_found' => __( 'Not found', 'genesis' ),
'not_found_in_trash' => __( 'Not found in Trash', 'genesis' ),
'items_list' => __( 'Items list', 'genesis' ),
'items_list_navigation' => __( 'Items list navigation', 'genesis' ),
'filter_items_list' => __( 'Filter items list', 'genesis' ),
);
$args = array(
'label' => __( 'Kollektion', 'genesis' ),
'description' => __( 'Kollektionen', 'genesis' ),
'labels' => $labels,
'supports' => array( 'title', 'editor', 'excerpt', 'author', 'thumbnail', ),
'taxonomies' => array( 'post_tag', 'kollektionen' ),
'hierarchical' => false,
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'menu_position' => 5,
'show_in_admin_bar' => true,
'show_in_nav_menus' => true,
'can_export' => true,
'has_archive' => 'kollektion',
'exclude_from_search' => false,
'publicly_queryable' => true,
'capability_type' => 'page',
);
register_post_type( 'kollektion', $args );

}
add_action( 'init', 'post_type_kollektion');
}

function namespace_add_custom_types( $query ) {
if( is_category() || is_tag() && empty( $query->query_vars['suppress_filters'] ) ) {
$query->set( 'post_type', array(
'post', 'nav_menu_item', 'kollektion', 'kollektionen'
));
return $query;
}
}
add_filter( 'pre_get_posts', 'namespace_add_custom_types' );

最佳答案

看起来您的分类和自定义帖子类型具有相同的别名。尝试更改分类法(或 CPT)并重新保存永久链接 - 这应该会有所帮助。

关于php - WordPress - 自定义帖子类型单页上出现 404 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33766187/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com