大家好,我已经为该自定义帖子类型创建了自定义帖子和自定义词条,但不知道为什么该词条没有显示在管理菜单栏下,请查看代码。veirfy 是我的自定义帖子类型。
function pluginprefix_setup_post_taxonomy()
{
define( 'TLC_PLUGIN_PATH', plugin_dir_url( __FILE__ ) );
define( 'TLC_PLUGIN_FULL_PATH', plugin_dir_path( __FILE__ ) );
// PCI DSS certificates
$labels_taxonomy = array(
'name' => 'Lead Assessors',
'singular_name' => 'Lead Assessor',
'menu_name' => 'Lead Assessor',
'all_items' => 'All Lead Assessors',
'parent_item' => 'Parent type',
'view_item' => 'View Lead Assessor',
'add_new_item' => 'Add Lead Assessor',
'add_new' => 'Add New Lead Assessor',
'show_in_menu' => 'Lead Assessor',
'edit_item' => 'Edit Lead Assessor',
'update_item' => 'Update Lead Assessor',
'search_items' => 'Search Lead Assessor',
'not_found' => 'Lead Assessors',
'not_found_in_trash' => 'Not found in Trash',
);
$args_taxonomy = array(
'hierarchical'=>true,
'labels' => $labels_taxonomy,
'query_var' => true,
'show_ui' => true,
// 'show_admin_column' => true,
'public' => true,
'show_in_nav_menus' => true,
'rewrite' => array('slug' =>'lead_assessor'),
);
// Registering your Custom taxonomy Type
register_taxonomy( 'lead_assessor', 'verify', $args_taxonomy );
// added in v3.0
flush_rewrite_rules();
}
add_action( 'init', 'pluginprefix_setup_post_taxonomy' );
答案 0 :(得分:0)
我认为您的帖子类型名称和分类名称相同,所以请检查。
或
您可以使用以下代码创建帖子类型和分类法。
/**
* Register a custom post type called "LA Posts".
*
* @see get_post_type_labels() for label keys.
*/
function cptui_register_my_cpts() {
/**
* Post Type: LA Posts.
*/
$labels = array(
"name" => __( "LA Posts" ),
"singular_name" => __( "LA Post" ),
);
$args = array(
"label" => __( "LA Posts" ),
"labels" => $labels,
"description" => "",
"public" => true,
"publicly_queryable" => true,
"show_ui" => true,
"delete_with_user" => false,
"show_in_rest" => true,
"rest_base" => "",
"rest_controller_class" => "WP_REST_Posts_Controller",
"has_archive" => true,
"show_in_menu" => true,
"show_in_nav_menus" => true,
"exclude_from_search" => false,
"capability_type" => "post",
"map_meta_cap" => true,
"hierarchical" => false,
"rewrite" => array( "slug" => "la_posts", "with_front" => true ),
"query_var" => true,
"supports" => array( "title", "editor", "thumbnail", "excerpt" ),
);
register_post_type( "la_posts", $args );
}
add_action( 'init', 'cptui_register_my_cpts' );
function cptui_register_my_taxes() {
/**
* Taxonomy: Lead Assessors.
*/
$labels_taxonomy = array(
'name' => 'Lead Assessors',
'singular_name' => 'Lead Assessor',
'menu_name' => 'Lead Assessor',
'all_items' => 'All Lead Assessors',
'parent_item' => 'Parent type',
'view_item' => 'View Lead Assessor',
'add_new_item' => 'Add Lead Assessor',
'add_new' => 'Add New Lead Assessor',
'show_in_menu' => 'Lead Assessor',
'edit_item' => 'Edit Lead Assessor',
'update_item' => 'Update Lead Assessor',
'search_items' => 'Search Lead Assessor',
'not_found' => 'Lead Assessors',
'not_found_in_trash' => 'Not found in Trash',
);
$args_taxonomy = array(
'hierarchical' =>true,
'labels' => $labels_taxonomy,
'query_var' => true,
'show_ui' => true,
'public' => true,
'show_in_nav_menus' => true,
'rewrite' => array('slug' =>'lead_assessor'),
);
register_taxonomy( "lead_assessor", array( "la_posts" ), $args_taxonomy );
}
add_action( 'init', 'cptui_register_my_taxes' );