I've tried many things to fix this, I'm fairly new to coding a plugin but I can't seem to get this to work.
I have created a custom post type ("Book") perfectly fine. Now I'm trying to add meta-boxes into it. I can't seem to get the coding to connect to each other properly.
I've tried adding the slugs of each meta box to the "support", I've tried various instances of function and add_meta_box as well as putting different things under "register_meta_box_cb" and nothing I'm doing seems to be working.
Any help is appreciated.
// Register Custom Post Type
function post_type_book() {
$args = array(
'label' => __( 'book', 'author_station' ),
'description' => __( 'Custom Book Entry', 'author_station' ),
'supports' => array('title'),
'taxonomies' => array( 'genres', 'series', 'tags' ),
'register_meta_box_cb' => ('as_add_book' ),
'labels' => $labels,
'hierarchical' => false,
'public' => true,
'show_ui' => true,
'show_in_menu' => false,
'menu_position' => 20,
'show_in_admin_bar' => true,
'show_in_nav_menus' => true,
'can_export' => true,
'has_archive' => true,
'exclude_from_search' => false,
'publicly_queryable' => true,
'rewrite' => array('slug' => 'Book'),
'capability_type' => 'page',
);
register_post_type( 'as_book', $args );
}
function as_add_book( $meta_boxes ) {
add_meta_box(
'add_meta_boxes',
array( $this, 'as_add_book_boxes' ));
$types = array('post', 'page', 'book');
if (in_array($types)) {
add_meta_box(
'as_add_book',
'add_meta_boxes',
'Book',
'as_add_book_callback',
$types,
'normal',
'high'
);
}
$prefix = 'as_';
$meta_boxes[] = array(
'id' => 'as_add_book',
'title' => esc_html__( 'Book', 'author_station_book' ),
'pages'=> array('as_book'),
'context' => 'advanced',
'priority' => 'high',
'autosave' => 'false',
'fields' => array(
array(
'id' => $prefix . 'book_cover',
'type' => 'image',
'name' => esc_html__( 'Book Cover', 'author_station_book' ),
),
array(
'id' => $prefix . 'book_title',
'type' => 'text',
'name' => esc_html__( 'Title', 'author_station_book' ),
),
);
return $meta_boxes;
}
add_filter( 'rwmb_meta_boxes', 'as_add_book' );