taxonomy like tags return 404 to custom post types

It works, the tags are displayed in the loop, But when click one of the tags return the error 404.

function my_custom_postpizza_product() {
  $labels = array(
    'name'               => _x( 'Pizza', 'post type general name' ),
    'singular_name'      => _x( 'Pizza', 'post type singular name' ),
    'add_new'            => _x( 'Añadir Nueva', 'entrada en Pizza' ),
    'add_new_item'       => __( 'Añadir Nueva entrada en Pizza' ),
    'edit_item'          => __( 'Modificar entrada en Pizza' ),
    'new_item'           => __( 'Nueva entrada en Pizza' ),
    'all_items'          => __( 'Todos las entrada en Pizza' ),
    'view_item'          => __( 'Ver entrada en Pizza' ),
    'search_items'       => __( 'Buscar entrada en Pizza' ),
    'not_found'          => __( 'Ninguna entrada en Pizza' ),
    'not_found_in_trash' => __( 'Ninguna entrada en Pizza encontrada en la la papelera' ),
    'parent_item_colon'  => '',
    'menu_icon' => get_bloginfo('template_directory'). '/images/my_menu_icon.png',
    'menu_name'          => 'Pizza'
  );

  $args = array(
    'labels'        => $labels,
    'description'   => 'Introduzca un nueva entrada en Pizza',
    'public'        => true,
    'menu_position' => 5,
    'supports'      => array( 'title', 'editor', 'thumbnail', 'excerpt', 'custom-fields', 'comments', 'revisions' ),
    'has_archive'   => true,
    'hierarchical'  => true,
    'rewrite'   => array('slug' => 'Pizza/%generos%','with_front' => false),
    'query_var'   => true,
    //'rewrite'   => true,
    //'publicly_queryable' => false,
  );
  register_post_type( 'Metal', $args );
    flush_rewrite_rules();

}
add_action( 'init', 'my_custom_postpizza_product' );


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' => 'metal' ),
    '_builtin'    => false,
  );
  register_taxonomy( 'generos', 'pizza', $args );
}
add_action( 'init', 'my_taxonomies_productpizza', 0 );

All the code works fine, but in this code below I have problems, the tags appears fine in the loop, but when i click on some tag, return error 404 I have also created the template tag.php, tag-pizza.php and resetting permalink.

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
  ));

}

Read more here: taxonomy like tags return 404 to custom post types

Leave a Reply

Your email address will not be published. Required fields are marked *