Okay, I got this and all things are good but it will not display the posts because we have to add them in every post, is it possible that the same name or slug will take the tags posts.
/** CITIES **/
/*
* Add Custom Taxonomies
*/
function cities_custom_taxonomies() {
$taxonomies = array(
// Director
array(
'name' => 'city', // here the name of the taxonomy
'single' => 'City', // here the single taxonomy name to show in the backend
'plural' => 'Cities', // here the plural taxonomy name to show in the backend
'cpt' => 'post' ), // which Custom Post Type to associate the taxonomy
);
foreach ($taxonomies as $taxonomy) {
$name = $taxonomy['name'];
$single = $taxonomy['single'];
$plural = $taxonomy['plural'];
$cpt = $taxonomy['cpt'];
$labels = array(
'name' => _x( $plural, 'taxonomy general name' ),
'singular_name' => _x( $single, 'taxonomy singular name' ),
'search_items' => __( 'Search '. $plural ),
'all_items' => __( 'All '. $plural ),
'parent_item' => __( 'Parent '. $single ),
'parent_item_colon' => __( 'Parent '. $single.':' ),
'edit_item' => __( 'Edit '. $single ),
'update_item' => __( 'Update '. $single ),
'add_new_item' => __( 'Add New '. $single ),
'new_item_name' => __( 'New Name '. $single ),
'menu_name' => __( $plural )
);
$args = array(
'labels' => $labels,
'hierarchical' => true, // false: as Tags, true: as Category
'show_ui' => true,
'show_admin_column' => true
);
register_taxonomy( $name, $cpt, $args );
} //foreach
}
add_action( 'init', 'cities_custom_taxonomies', 0 );
You can get a custom template to be used for certain situations by properly naming the template file. See
https://developer.wordpress.org/themes/basics/template-hierarchy/#custom-taxonomies
In some cases the default taxonomy term query doesn’t pick up the post types that you want it to. You can modify the query through the “pre_get_posts” action and set the “post_type” query var to the desired post type or array of types.
https://developer.wordpress.org/reference/hooks/pre_get_posts/
Thanks, I’ll do more research on that. Regards.