I have a Custom Post Type like
function cpt_Projects() {
$labels = array(
'name' => 'Projects',
'singular_name' => 'Project',
'menu_name' => 'Projects',
'name_admin_bar' => 'Projects',
'parent_item_colon' => 'Parent Projects:',
'all_items' => 'All Projects',
'view_item' => 'View Project',
'add_new_item' => 'Add New Project',
'add_new' => 'Add New Project',
'new_item' => 'New Projects',
'edit_item' => 'Edit Project Item',
'update_item' => 'Update Project Item',
'search_items' => 'Search Project Item',
'not_found' => 'Project Not found',
'not_found_in_trash' => 'Project Not found in Trash',
);
$args = array(
'label' => 'ProjectsCPT',
'description' => 'This Post Type Adds Eyeglasses to Website',
'labels' => $labels,
'supports' => array( 'title', 'thumbnail', 'editor'),
'taxonomies' => array( 'ProjectsTax' ),
'register_meta_box_cb' => 'add_details_metabox',
'hierarchical' => true,
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'show_in_nav_menus' => true,
'show_in_admin_bar' => true,
'menu_position' => 5,
'can_export' => true,
'has_archive' => true,
'exclude_from_search' => false,
'publicly_queryable' => true,
'capability_type' => 'post',
);
register_post_type( 'ProjectsCPT', $args );
}
add_action( 'init', 'cpt_Projects', 0 );
and a Metabox like
function add_details_metabox($post_type) {
$types = array('post', 'page', 'ProjectsCPT');
if (in_array($post_type, $types)) {
add_meta_box(
'details-metabox',
'Project Details',
'detail_meta_callback',
$post_type,
'normal',
'high'
);
}
}
after running the code the Metabox is showing on all Page
s and Post
s but not on Custom Post Type ProjectsCPT
Can you please let me know what I am doing wrong? (It works fine if I remove the if statement
if (in_array($post_type, $types)) {}
but this add metabox to all Posts and Pages which is not what I need to do