I've added this code to my magazine.php file into the plugin, but when it is activated, the CPT does not appear in the dashboard menu. Do you figure out why? it is a really minimalistic CPT, i do not understand why it does not work...
add_action('init', 'mc_setup_post_type');
function mc_activation(){
// trigger the wp function that registers the custom post type
mc_setup_post_type();
//clear the permalinks after the post type has been registered
flush_rewrite_rules();
}
function mc_setup_post_type(){
//register the "magazine" custom post type
register_post_type('magazine', array(
'labels' => array(
'name' => 'magazine'),
'public' => 'true'));
}
I've added this code to my magazine.php file into the plugin, but when it is activated, the CPT does not appear in the dashboard menu. Do you figure out why? it is a really minimalistic CPT, i do not understand why it does not work...
add_action('init', 'mc_setup_post_type');
function mc_activation(){
// trigger the wp function that registers the custom post type
mc_setup_post_type();
//clear the permalinks after the post type has been registered
flush_rewrite_rules();
}
function mc_setup_post_type(){
//register the "magazine" custom post type
register_post_type('magazine', array(
'labels' => array(
'name' => 'magazine'),
'public' => 'true'));
}
Share
Improve this question
edited Jun 8, 2019 at 4:45
jaze
901 gold badge1 silver badge6 bronze badges
asked Jun 8, 2019 at 4:06
Raul Magdalena CatalaRaul Magdalena Catala
113 bronze badges
2
|
1 Answer
Reset to default 2The problem is that you've set the value for 'public'
incorrectly. That argument is a boolean, meaning it's true
or false
, and in PHP these need to be written without quotes to be correct:
register_post_type(
'magazine',
array(
'labels' => array(
'name' => 'magazine',
),
'public' => true,
)
);
For the post type to appear in the admin sidebar, 'show_in_menu'
needs to be true
. The default value of 'show_in_menu'
— if it's not provided — is the same as 'show_ui'
, which itself defaults to the value of 'public'
. this is why 'public'
being set incorrectly was causing the problem.
The reason Pravin's answer works is because he's manually setting 'show_in_menu'
to true
. But while this makes the post type appear in the admin menu, it's still not set to public correctly, which means that the post type still won't be publicly visible. The 'show_in_menu'
argument is not required if 'public'
is set correctly.
magazine.php
included somewhere or it's an orphan file? Please make clear what your plugin is. – Max Yudin Commented Jun 8, 2019 at 6:10