I am working on a custom theme for a network of sites that are deployed under a WordPress MultiSite installation.
Within these theme I create 4 custom post types that have two taxonomies added to all of them. The first taxonomy is the post_tag
one and the other is a a custom taxonomy that resembles the category
one.
I've chosen that all of my 4 custom post types to have their own taxonomy category because I did not want any category bleed within the post types.
Here is my code:
<?php
function o_post_types()
{
$post_types = array(
'articole' => array(
'name' => 'Articole',
'single' => 'Articol',
'icon' => 'dashicons-admin-post'
),
'evenimente' => array(
'name' => 'Evenimente',
'single' => 'Eveniment',
'icon' => 'dashicons-video-alt'
),
'concursuri' => array(
'name' => 'Concursuri',
'single' => 'Concurs',
'icon' => 'dashicons-awards'
),
'fotografii' => array(
'name' => 'Fotografii',
'single' => 'Fotografie',
'icon' => 'dashicons-format-image'
),
'promotii' => array(
'name' => 'Promoții',
'single' => 'Promoție',
'icon' => 'dashicons-share'
)
);
foreach ($post_types as $post_type) {
$icon = $post_type['icon'];
$name_lower = strtolower($post_type['name']);
$single_lower = strtolower($post_type['single']);
if ($post_type['name'] == 'Promoții') {
$name_lower = 'promotii';
$single_lower = 'promotie';
}
$labels = array(
'name' => $post_type['name'],
'singular_name' => $post_type['single'],
'add_new' => 'Adaugă ' . $single_lower,
'add_new_item' => 'Adaugă ' . $single_lower . ' nou',
'edit_item' => 'Editează ' . $single_lower,
'new_item' => $post_type['single'] . ' nou',
'all_items' => 'Listă ' . $name_lower,
'view_item' => 'Afișează ' . $single_lower,
'search_items' => 'Caută în ' . $name_lower,
'not_found' => 'Nici un ' . $single_lower . ' găsit.',
'not_found_in_trash' => 'Nici un ' . $single_lower . ' găsit în Gunoi.',
'parent_item_colon' => '',
'menu_name' => $post_type['name']
);
$args = array(
'labels' => $labels,
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'show_in_menu' => true,
'query_var' => true,
'rewrite' => array('slug' => $name_lower, 'with_front' => false),
'capability_type' => 'post',
'has_archive' => true,
'hierarchical' => false,
'menu_position' => 5,
'supports' => array('title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments'),
'taxonomies' => array('post_tag'),
'menu_icon' => $icon
);
register_post_type("cpt_" . $single_lower, $args);
$labels = array(
'name' => 'Categorii',
'singular_name' => 'Categorie',
'search_items' => 'Caută Categorii',
'all_items' => 'Toate Categoriile',
'parent_item' => 'Categorie Părinte',
'parent_item_colon' => 'Categorie Părinte:',
'edit_item' => 'Modifică Categorie',
'update_item' => 'Actualizează Categorie',
'add_new_item' => 'Adaugă Categorie nouă',
'new_item_name' => 'Numele noii categorii',
'menu_name' => 'Categorii',
);
$args = array(
'hierarchical' => true,
'labels' => $labels,
'show_ui' => true,
'show_admin_column' => true,
'query_var' => true,
'rewrite' => array(
'hierarchical' => true,
'slug' => $name_lower,
'with_front' => false
),
);
register_taxonomy("tax_" . $name_lower, "cpt_" . $single_lower, $args);
}
}
EDIT 1*
The file names are as follow:
taxonomy-articole.php
taxonomy-concursuri.php
taxonomy-evenimente.php
taxonomy-fotografii.php
taxonomy-promotii.php
I am trying to display a list as a category view of all cpt
s that have that term. Ex: a cpt_evenimente
(or cpt_events
in English) will have a tax_evenimente
term (or tax_events
in English) like so:
Skate-park skateboard showoff cpt
will have assigned a Outdoor Event term
and it will have to be displayed because of its term in the taxonomy-evenimente.php
loop.
The problem is that the templates for each taxonomy does not load. What is there to be done?
cpt
s that belong to all terms found within a certain taxonomy for now.tax_evenimente
, the template should betaxonomy-tax_evenimente.php
.