You can achieve your goal by registering a custom taxonomy for your Custom Post as follows (I will assume that the post type is called product, and that taxonomy is called product type):
/* Action para o registro da Custom Taxonomy Tipo de Produto */
add_action( 'init', 'create_custom_tax_tipo' );
/* Método para o registro da Custom Taxonomy Tipo de Produto */
function create_custom_tax_tipo(){
$custom_tax_nome = 'tipo_de_produto';
$custom_post_type_nome = 'produto';
$args = array(
'label' => __('Tipo de Produto'),
'hierarchical' => true,
'rewrite' => array('slug' => 'tipo')
);
register_taxonomy( $custom_tax_nome, $custom_post_type_nome, $args );
}
Put this code in your plugin files or in your functions.php
. Stay tuned for the way you baptize your Custom Posts and Custom Taxonomies. The use of words like Category (which should be a reserved word in WP) can be harmful.
More about the method register_taxonomy()
on Codex.
If you want to add categories default in the Custom Post, that is, without registering a taxonomy in a programmatic way, you can provide this information when registering the Custom Post. Remember which category is basically a taxonomy. So, at the end of the day, the result will be the same. The registration code would be something like
register_post_type('produto',
array(
'labels' => array(
//todos os seus labels
),
'public' => true,
'show_ui' => true,
'supports' => array( 'title', 'editor', 'thumbnail' ),
// ...
//todo o resto dos seus parâmetros de criação
// ...
'taxonomies' => array('category'), // <=== habilita o uso de categorias por default
)
);
Thank you so much for your reply. It worked perfectly!
– Diegooli
@Diegooli arrange
– Caio Felipe Pereira