我已经找到了答案,我完全误解了标准帖子类型和自定义帖子类型之间的区别,以及它们的分类法。我发现了几篇非常有用的文章,下面的代码就是我最终得到的,还有一些我觉得有用的文章。我希望其他人觉得这很有用。
// Load Custom Post Type
function add_directory() {
$labels = array(
\'name\' => __( \'Businesses\', \'text_domain\' ),
\'singular_name\' => __( \'Business\', \'text_domain\' ),
\'add_new\' => __( \'Add New Business\', \'${4:Name}\', \'text_domain\' ),
\'add_new_item\' => __( \'Add New Business\', \'text_domain}\' ),
\'edit_item\' => __( \'Edit Business\', \'text_domain\' ),
\'new_item\' => __( \'New Business\', \'text_domain\' ),
\'view_item\' => __( \'View Business\', \'text_domain\' ),
\'search_items\' => __( \'Search Businesses\', \'text_domain\' ),
\'not_found\' => __( \'No Businesses found\', \'text_domain\' ),
\'not_found_in_trash\' => __( \'No Businesses found in Trash\', \'text_domain\' ),
\'parent_item_colon\' => __( \'Parent Business:\', \'text_domain\' ),
\'menu_name\' => __( \'Business Directory\', \'text_domain\' ),
);
$args = array(
\'labels\' => $labels,
\'hierarchical\' => true,
\'description\' => \'description\',
\'taxonomies\' => array( \'biz-cat\' ),
\'public\' => true,
\'show_ui\' => true,
\'show_in_menu\' => true,
\'menu_position\' => 5,
//\'menu_icon\' => \'\',
\'show_in_nav_menus\' => true,
\'publicly_queryable\' => true,
\'exclude_from_search\' => false,
\'has_archive\' => true,
\'query_var\' => true,
\'can_export\' => true,
\'rewrite\' => true,
\'capability_type\' => \'post\',
\'supports\' => array( \'title\', \'editor\', \'author\', \'thumbnail\', \'custom-fields\', \'revisions\', \'post-formats\' ),
);
register_post_type( \'bizdirectory\', $args );
}
add_action( \'init\', \'add_directory\' );
// Create Custom Taxonomy
function directory_create_taxonomies()
{
register_taxonomy( \'biz-cat\', array( \'bizdirectory\' ), array(
\'hierarchical\' => true,
\'label\' => \'Business Categories\',
\'singular_name\' => \'Business Category\',
\'show_ui\' => true,
\'query_var\' => true,
\'rewrite\' => array( \'slug\' => \'biz-cat\' )
));
}
add_action( \'init\', \'directory_create_taxonomies\', 0 );
// \'bizdirectory\' is the registered post type name
function directory_columns($defaults) {
// \'biz-cat\' is the registered taxonomy name
$defaults[\'biz-cat\'] = \'Business Category\';
return $defaults;
}
function directory_custom_column($column_name, $post_id) {
$taxonomy = $column_name;
$post_type = get_post_type($post_id);
$terms = get_the_terms($post_id, $taxonomy);
if ( !empty($terms) ) {
foreach ( $terms as $term )
$post_terms[] = "<a href=\'edit.php?post_type={$post_type}&{$taxonomy}={$term->slug}\'> " . esc_html(sanitize_term_field(\'name\', $term->name, $term->term_id, $taxonomy, \'edit\')) . "</a>";
echo join( \', \', $post_terms );
}
else echo \'<i>Not assigned.</i>\';
}
add_filter( \'manage_project_posts_columns\', \'directory_columns\' );
add_action( \'manage_project_posts_custom_column\', \'directory_custom_column\', 10, 2 );