There is an assorted list of issues on your code.
When I load your code I’m not seeing the same thing you do. I’m seeing it create a second posts
section and a second pages
section, which is what it should be doing because you set one to hierarchical
and one not.
The primary issue is that you’re using capabilities
wrong. it uses default WordPress Capabilities. Perhaps you meant edit_posts
? If you don’t want any special capabilities to use this post, then just delete that line in both register_post_type
args. In fact, delete all cap
lines.
Next is you’re not setting labels, in fact you’re deleting your labels. The point of of custom post types is to customize. Give the post a meaningful name here:
'label' => NULL,
should be
'label' => 'posttype2',
Better yet change this to assign specific labels in a labels
ARRAY (see the documentation for what all you can do here)
Then you set menu icon to NULL
. If you want a generic menu icon, get rid of this line. if you’re trying to add one with CSS, then replace with 'none'
.
Lastly, you set rewrite
and query_var
to TRUE. I’m not sure why. If you’re not customizing it, just let it be and delete these lines.
I would take a minute to look over the register_post_type options and add a labels array and I would also take the opportunity to create a more custom post_type name when registering it as well.
TL / DR
This should be your code below. (I’ve added sample labels but you should replace with your own post names).
add_action('init', 'register_post1');
function register_post1(){
register_post_type( 'post2', array(
'label' => 'books',
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'show_in_rest' => true,
'menu_position' => 6,
'taxonomies' => array('taxo1'), //'big_event_name',
'hierarchical' => true,
'has_archive' => false
));
}
add_action('init', 'register_post_2');
function register_post_2(){
register_post_type( 'post1', array(
'label' => 'grains',
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'show_in_rest' => true,
'menu_position' => 7,
'taxonomies' => array('taxo2'),
'hierarchical' => false,
'has_archive' => false
));
}