📦 register_post_type()
add_action('init', function () {
register_post_type('libro', [
'label' => 'Libros',
'public' => true,
'has_archive' => true,
'rewrite' => ['slug' => 'libros'],
'menu_icon' => 'dashicons-book',
'supports' => ['title', 'editor', 'thumbnail', 'custom-fields'],
'show_in_rest' => true,
]);
});
🏷️ register_taxonomy()
add_action('init', function () {
register_taxonomy('genero', 'libro', [
'label' => 'Géneros',
'hierarchical' => true,
'public' => true,
'rewrite' => ['slug' => 'generos'],
'show_in_rest' => true,
]);
});
🔗 Relación entre CPT y Taxonomía personalizada
En
register_taxonomy(), asegúrate de asignar el CPT en el segundo parámetro ('libro'en el ejemplo).Puedes asociar una misma taxonomía a varios CPTs usando un array:
register_taxonomy('tema', ['libro', 'curso'], [...]);