It works, the tags are displayed in the loop, But when entering one of the tags appears the error 404 I have also created a template tag-pizza.php
Here code of the tags
add_action( 'init', 'create_tag_taxonomies', 0 );
function create_tag_taxonomies()
{
// Add new taxonomy, NOT hierarchical (like tags)
$labels = array(
'name' => _x( 'Tags', 'taxonomy general name' ),
'singular_name' => _x( 'Tag', 'taxonomy singular name' ),
'search_items' => __( 'Search Tags' ),
'popular_items' => __( 'Popular Tags' ),
'all_items' => __( 'All Tags' ),
'parent_item' => null,
'parent_item_colon' => null,
'edit_item' => __( 'Edit Tag' ),
'update_item' => __( 'Update Tag' ),
'add_new_item' => __( 'Add New Tag' ),
'new_item_name' => __( 'New Tag Name' ),
'separate_items_with_commas' => __( 'Separate tags with commas' ),
'add_or_remove_items' => __( 'Add or remove tags' ),
'choose_from_most_used' => __( 'Choose from the most used tags' ),
'menu_name' => __( 'Tags' ),
);
register_taxonomy('tag','pizza',array(
'hierarchical' => false,
'labels' => $labels,
'show_ui' => true,
'update_count_callback' => '_update_post_term_count',
'query_var' => true,
'rewrite' => array( 'slug' => 'tag' ),
'with_front' => true
));
}
here code of taxonomy principal
function my_taxonomies_productpizza() {
$labels = array(
'name' => _x( 'Generos', 'taxonomy general name' ),
'singular_name' => _x( 'Generos', 'taxonomy singular name' ),
'search_items' => __( 'Search Product Categories' ),
'all_items' => __( 'All Product Categories' ),
'parent_item' => __( 'Parent Product Category' ),
'parent_item_colon' => __( 'Parent Product Category:' ),
'edit_item' => __( 'Edit Product Category' ),
'update_item' => __( 'Update Product Category' ),
'add_new_item' => __( 'Add New Product Category' ),
'new_item_name' => __( 'New Product Category' ),
'menu_name' => __( 'Generos' ),
);
$args = array(
'labels' => $labels,
'hierarchical' => true,
'public' => true,
'query_var' => 'generos',
//slug prodotto deve coincidere con il primo parametro dello slug del Custom Post Type correlato
'rewrite' => array('slug' => 'pizza' ),
'_builtin' => false,
);
register_taxonomy( 'generos', 'pizza', $args );
}
add_action( 'init', 'my_taxonomies_productpizza', 0 );
It works, the tags are displayed in the loop, But when entering one of the tags appears the error 404 I have also created a template tag-pizza.php
Here code of the tags
add_action( 'init', 'create_tag_taxonomies', 0 );
function create_tag_taxonomies()
{
// Add new taxonomy, NOT hierarchical (like tags)
$labels = array(
'name' => _x( 'Tags', 'taxonomy general name' ),
'singular_name' => _x( 'Tag', 'taxonomy singular name' ),
'search_items' => __( 'Search Tags' ),
'popular_items' => __( 'Popular Tags' ),
'all_items' => __( 'All Tags' ),
'parent_item' => null,
'parent_item_colon' => null,
'edit_item' => __( 'Edit Tag' ),
'update_item' => __( 'Update Tag' ),
'add_new_item' => __( 'Add New Tag' ),
'new_item_name' => __( 'New Tag Name' ),
'separate_items_with_commas' => __( 'Separate tags with commas' ),
'add_or_remove_items' => __( 'Add or remove tags' ),
'choose_from_most_used' => __( 'Choose from the most used tags' ),
'menu_name' => __( 'Tags' ),
);
register_taxonomy('tag','pizza',array(
'hierarchical' => false,
'labels' => $labels,
'show_ui' => true,
'update_count_callback' => '_update_post_term_count',
'query_var' => true,
'rewrite' => array( 'slug' => 'tag' ),
'with_front' => true
));
}
here code of taxonomy principal
function my_taxonomies_productpizza() {
$labels = array(
'name' => _x( 'Generos', 'taxonomy general name' ),
'singular_name' => _x( 'Generos', 'taxonomy singular name' ),
'search_items' => __( 'Search Product Categories' ),
'all_items' => __( 'All Product Categories' ),
'parent_item' => __( 'Parent Product Category' ),
'parent_item_colon' => __( 'Parent Product Category:' ),
'edit_item' => __( 'Edit Product Category' ),
'update_item' => __( 'Update Product Category' ),
'add_new_item' => __( 'Add New Product Category' ),
'new_item_name' => __( 'New Product Category' ),
'menu_name' => __( 'Generos' ),
);
$args = array(
'labels' => $labels,
'hierarchical' => true,
'public' => true,
'query_var' => 'generos',
//slug prodotto deve coincidere con il primo parametro dello slug del Custom Post Type correlato
'rewrite' => array('slug' => 'pizza' ),
'_builtin' => false,
);
register_taxonomy( 'generos', 'pizza', $args );
}
add_action( 'init', 'my_taxonomies_productpizza', 0 );
Share
Improve this question
edited Apr 17, 2017 at 6:28
fuxia♦
107k38 gold badges255 silver badges459 bronze badges
asked Apr 8, 2017 at 21:14
MaxMax
536 bronze badges
1
- The built in post_tag taxonomy already uses the URL /tag/ by default. Have you inspected the query and verified that it is for the correct taxonomy? – Milo Commented Apr 17, 2017 at 15:19
2 Answers
Reset to default 1Try resetting permalink.
Go to Settings -> Permalinks and hit save on that page.
Try if tags are working now.
When using the 'tag' name for your custom taxonomy, do not set the query_var parameter to just true. Use a custom string, for example:
register_taxonomy('tag', 'pizza', array(
'query_var' => 'p',
'rewrite' => array( 'slug' => 'tag' ),
));