Ramon Vasconcelos
Ramon Vasconcelos

Reputation: 945

Custom post type category permalink returns 404

I created a custom post type called Produtos:

    $labels = array( 
    'name' => _x( 'Produtos', 'produto' ),
    'singular_name' => _x( 'produto', 'produto' ),
    'add_new' => _x( 'Adicionar', 'produto' ),
    'add_new_item' => _x( 'Novo produto', 'produto' ),
    'edit_item' => _x( 'Editar produto', 'produto' ),
    'new_item' => _x( 'Novo produto', 'produto' ),
    'view_item' => _x( 'Ver produto', 'produto' ),
    'search_items' => _x( 'Buscar produto', 'produto' ),
    'not_found' => _x( 'Nenhum produto encontrado', 'produto' ),
    'not_found_in_trash' => _x( 'Nenhum produto encontrado na lixeira', 'produto' ),
    'parent_item_colon' => _x( 'Parent produto:', 'produto' ),
    'menu_name' => _x( 'Produtos', 'produto' ),
);

$args = array( 
    'labels' => $labels,
    'hierarchical' => true,

    'supports' => array( 'title'),

    'public' => true,
    'show_ui' => true,
    'show_in_menu' => true,
    'menu_position' => 5,

    'show_in_nav_menus' => true,
    'publicly_queryable' => true,
    'exclude_from_search' => false,
    'has_archive' => true,
    'query_var' => true,
    'can_export' => true,
    'rewrite' => true,
    'capability_type' => 'post',
    'taxonomies' => array( 'category' )
);

register_post_type( 'produtos', $args );

add_post_type_support( 'produtos', 'post-formats' );

Than i created its category:

add_action( 'init', 'create_my_taxonomies', 0 );
function create_my_taxonomies() {
    register_taxonomy(
        'categoria_produtos',
        'produtos',
        array(
            'labels' => array(
                'name' => 'Categorias de produto',
                'add_new_item' => 'Adicionar nova categoria',
                'new_item_name' => "Nova categoria de portfolio"
            ),
            'show_ui' => true,
            'show_tagcloud' => false,
            'query_var' => true,
            'hierarchical' => true,
            'rewrite' => array(
                'slug' => 'produtos/categoria_produtos'
            )
        )
    );
}

It's working fine, registering data, etc. but when i click on category it returns me 404. Im a beginner wp dev.. i cant figure it out why its not working, can somebody help me?

Upvotes: 0

Views: 71

Answers (1)

Ryan
Ryan

Reputation: 2503

Have you re-saved your Permalink structure since creating the Custom Post Type? If not, I would recommend doing so, by navigating to Settings > Permalinks and then clicking the "Save Changes" button. This should resolve the issue.

Upvotes: 0

Related Questions