我创建了关于投资组合的自定义帖子类型,我也曾经创建过分类法,这是投资组合类别,但是事情是当我创建任何帖子并为其分配一个类别时,所以发布该帖子后可见,但是类别在帖子中不可见,我不知道为什么帖子发布后隐藏了。谢谢
这是我的代码
/**
* custom post Portfolio_page.
*/
function custom_post_type() {
$labels = array(
'name' => __( 'portfolio' ),
'singular_name' => __( 'portfolio'),
'menu_name' => __( 'portfolios'),
'parent_item_colon' => __( 'Parent Deal'),
'all_items' => __( 'All portfolios'),
'view_item' => __( 'View portfolio'),
'add_new_item' => __( 'Add New portfolio'),
'add_new' => __( 'Add New'),
'edit_item' => __( 'Edit portfolio'),
'update_item' => __( 'Update portfolio'),
'search_items' => __( 'Search portfolio'),
'not_found' => __( 'Not Found'),
'not_found_in_trash' => __( 'Not found in Trash')
);
$args = array(
'label' => __( 'portfolio'),
'description' => __( 'Loops digital portfolio'),
'labels' => $labels,
'supports' => array( 'title', 'editor', 'excerpt', 'author', 'thumbnail', 'revisions', 'custom-fields'),
'public' => true,
'hierarchical' => false,
'show_ui' => true,
'show_in_menu' => true,
'show_in_nav_menus' => true,
'show_in_admin_bar' => true,
'has_archive' => true,
'can_export' => true,
'exclude_from_search' => false,
'publicly_queryable' => true,
'capability_type' => 'page'
);
register_post_type( 'portfolio', $args );
}
add_action( 'init', 'custom_post_type', 0 );
/**
* Custom Taxonomy for Custom post type
*/
add_action( 'init', 'custom_post_type_taxonomy', 0 );
function custom_post_type_taxonomy() {
$labels = array(
'name' => _x( 'portfolio_categories', 'taxonomy general name' ),
'singular_name' => _x( 'portfolio_category', 'taxonomy singular name' ),
'search_items' => __( 'Search portfolio_categories' ),
'all_items' => __( 'All portfolio_categories' ),
'parent_item' => __( 'Parent portfolio_categories' ),
'parent_item_colon' => __( 'Parent portfolio_categories:' ),
'edit_item' => __( 'Edit portfolio_categories' ),
'update_item' => __( 'Update portfolio_categories' ),
'add_new_item' => __( 'Add New portfolio_categories' ),
'new_item_name' => __( 'New portfolio_categories Name' ),
'menu_name' => __( 'portfolio_categories' ),
);
register_taxonomy('portfolio_categories',array('portfolio'), array(
'hierarchical' => true,
'labels' => $labels,
'show_ui' => true,
'show_admin_column' => true,
'query_var' => true,
'rewrite' => array( 'slug' => 'portfolio_categories' ),
));
}
答案 0 :(得分:0)
please try this function
function portfolio_post_type() {
$labels = array(
'name' => __( 'portfolio'),
'singular_name' => __( 'portfolio' ),
'add_new' => __( 'add portfolio'),
'add_new_item' => __( 'add portfolio' ),
'edit_item' => __( 'edit' ),
'new_item' => __( 'new portfolio' ),
'all_items' => __( ' all ' ),
'view_item' => __( 'view ' ),
'search_items' => __( 'searcj ' ),
'not_found' => __( 'nothing found' ),
'not_found_in_trash' => __( 'nothing found' ),
'parent_item_colon' => '',
'menu_name' => 'portfolio'
);
$args = array(
'label' => __( 'portfolio' ),
'description' => __( 'portfolio' ),
'labels' => $labels,
'supports' => array( 'title', 'editor', 'thumbnail', 'comments', 'custom-fields' ),
'taxonomies' => array( 'portfolio_portfolio' ),
'hierarchical' => false,
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'menu_position' => 5,
'show_in_admin_bar' => true,
'show_in_nav_menus' => true,
'show_in_rest' => true,
'can_export' => true,
'has_archive' => true,
'exclude_from_search' => false,
'publicly_queryable' => true,
'capability_type' => 'post',
);
register_post_type( 'portfolio', $args );
}
add_action( 'init', 'portfolio_post_type', 0 );
// Register Custom Taxonomy
function portfolio_portfolio_taxonomy() {
$labels = array(
'name' => __( 'portfolio', 'Taxonomy General Name' ),
'singular_name' => __( 'portfolio', 'Taxonomy Singular Name' ),
'menu_name' => __( 'portfolio' ),
'all_items' => __( 'all' ),
'parent_item' => __( 'Parent Item' ),
'parent_item_colon' => __( 'Parent Item:' ),
'new_item_name' => __( 'new' ),
'add_new_item' => __( 'new' ),
'edit_item' => __( 'edit' ),
'update_item' => __( 'update' ),
'view_item' => __( 'view' ),
'separate_items_with_commas' => __( 'Separate items with commas' ),
'add_or_remove_items' => __( 'Add or remove items' ),
'choose_from_most_used' => __( 'Choose from the most used' ),
'popular_items' => __( 'Popular Items' ),
'search_items' => __( 'Search Items' ),
'not_found' => __( 'Not Found' ),
'no_terms' => __( 'No items' ),
'items_list' => __( 'Items list' ),
'items_list_navigation' => __( 'Items list navigation' ),
);
$args = array(
'labels' => $labels,
'hierarchical' => true,
'public' => true,
'show_ui' => true,
'show_admin_column' => true,
'show_in_nav_menus' => true,
'show_tagcloud' => true,
'show_in_rest' => true
);
register_taxonomy( 'portfolio_portfolio', array( 'portfolio' ), $args );
}
add_action( 'init', 'portfolio_portfolio_taxonomy', 0 );