recently I am going through very wierd problem.
What I want:
I attempt to create plugin, which makes user able to create custom defined categories, and then display meta box at add
or edit
screen for my custom defined content type, called funny_band
.
Note:
I went through every possible documentation or tutorial possible. My project also does not contain any futher wierd plugins or theme modifications, I like to keep things simple.
The wierd part:
The same code below I have copied with different naming in another plugin. In first plugin it works, but does not work in the second. Naming clashes are not the case, i checked this for 10 times.
What I tried:
<?php
const MY_PLUGIN__CONTENT_TYPE_NAME = 'funny_band';
const MY_PLUGIN__TAXONOMY = 'funny_bands_categories';
function my_plugin__register_band_type(){
register_post_type(MY_PLUGIN__CONTENT_TYPE_NAME, [
'labels' => [
'name' => __('Bands'),
'singular_name' => __('Band'),
'add_new_item' => __('Add new Band'),
],
'menu_icon' => 'dashicons-groups',
'public' => true,
'menu_position' => 6,
'show_in_rest' => true,
'supports' => ['title', 'editor', 'thumbnail'],
]);
}
function my_plugin__register_taxonomies(){
$labels = [
'name' => 'Category',
'singular_name' => 'Category',
];
$category_args = [
'description' => 'Band categories',
'public' => true,
'hierarchical' => false,
'labels' => $labels,
'show_admin_column' => true,
'meta_box_cb' => function($post, $args){
error_log('This message is not visible!');
echo '<h1>Custom metabox_cb</h1>';
}
}
];
register_taxonomy(MY_PLUGIN__TAXONOMY, MY_PLUGIN__CONTENT_TYPE_NAME, $category_args);
register_taxonomy_for_object_type(MY_PLUGIN__TAXONOMY, MY_PLUGIN__CONTENT_TYPE_NAME);
}
add_action('init', 'my_plugin__register_band_type');
add_action('init', 'my_plugin__register_taxonomies');
Any ideas what can be wrong? I have no idea at all why it does not work.