我在自定义帖子类型、分类法、永久链接和重写方面遇到了问题。
我使用以下代码创建了一个自定义的“recipes”帖子类型和分类:
add_action(\'init\', \'recipes_register\');
function recipes_register() {
$labels = array(
\'name\' => __(\'Recipes\', \'framework\'),
\'singular_name\' => __(\'Recipe\', \'framework\'),
\'add_new\' => __(\'Add Recipe\', \'framework\'),
\'add_new_item\' => __(\'Add New Recipe\', \'framework\'),
\'edit_item\' => __(\'Edit Recipe\', \'framework\'),
\'new_item\' => __(\'New Recipe\', \'framework\'),
\'view_item\' => __(\'View Recipe\', \'framework\'),
\'search_items\' => __(\'Search Recipe\', \'framework\'),
\'not_found\' => __(\'Nothing found\', \'framework\'),
\'not_found_in_trash\' => __(\'Nothing found in Trash\', \'framework\'),
\'parent_item_colon\' => \'\'
);
$args = array(
\'labels\' => $labels,
\'public\' => true,
\'publicly_queryable\' => true,
\'show_ui\' => true,
\'query_var\' => true,
\'menu_icon\' => get_stylesheet_directory_uri() . \'/img/admin-recipes.png\',
\'rewrite\' => true,
\'capability_type\' => \'post\',
\'hierarchical\' => true,
\'menu_position\' => null,
\'supports\' => array(\'title\',\'editor\',\'thumbnail\',\'comments\'),
);
register_post_type( \'recipes\' , $args );
}
register_taxonomy(\'recipe_type\', array(\'recipes\'), array(\'hierarchical\' => true, \'label\' => __(\'Recipe Type\', \'framework\'), \'rewrite\' => array(\'hierarchical\' => true, \'slug\'=>\'recipes\')));
当我想使用这种URL访问自定义类型的帖子时,就会出现问题,它会抛出404错误:
http://my-website/recipes/name-of-the-recipe/
我认为问题是因为我想对分类法“recipe\\u type”和“recipe”自定义post类型使用相同的slug。
我对此有点困惑,如果你能帮我解决这个问题,我将不胜感激。
谢谢