最后,我使用了自定义分类法,它也更易于管理。我发布了以下内容:
//hook into the init action and call create_topics_nonhierarchical_taxonomy when it fires
add_action( \'init\', \'create_regions_nonhierarchical_taxonomy\', 0 );
function create_regions_nonhierarchical_taxonomy() {
// Labels part for the GUI
$labels = array(
\'name\' => _x( \'Regions\', \'Where are located activities or place of interests\' ),
\'singular_name\' => _x( \'Region\', \'Regions singular name\' ),
\'search_items\' => __( \'Search Regions\' ),
\'popular_items\' => __( \'Popular Regions\' ),
\'all_items\' => __( \'All Regions\' ),
\'parent_item\' => null,
\'parent_item_colon\' => null,
\'edit_item\' => __( \'Edit Region\' ),
\'update_item\' => __( \'Update Region\' ),
\'add_new_item\' => __( \'Add New Region\' ),
\'new_item_name\' => __( \'New Region Name\' ),
\'separate_items_with_commas\' => __( \'Separate regions with commas\' ),
\'add_or_remove_items\' => __( \'Add or remove regions\' ),
\'choose_from_most_used\' => __( \'Choose from the most used regions\' ),
\'menu_name\' => __( \'Regions\' ),
);
// Now register the non-hierarchical taxonomy like tag
register_taxonomy(\'regions\',\'post\',array(
\'hierarchical\' => false,
\'labels\' => $labels,
\'show_ui\' => true,
\'show_in_rest\' => true,
\'show_admin_column\' => true,
\'update_count_callback\' => \'_update_post_term_count\',
\'query_var\' => true,
\'rewrite\' => array( \'slug\' => \'region\', \'with_front\' => false),
));
}