我已经尝试了很多方法来解决这个问题,我对编写插件还是个新手,但是我似乎不能让它工作。
我已经创建了一个自定义的帖子类型("Book"),非常好。现在,我正在尝试将meta-boxes添加到其中。我似乎无法获得正确连接彼此的代码。
我已经尝试将每个元框的插件添加到“支持”中,我已经尝试了function和add_meta_box的各种实例,以及将不同的东西放在"register_meta_box_cb“下,但我所做的似乎都不起作用。
任何帮助都是非常感谢的。
// 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' );发布于 2020-05-17 04:57:49
add_action( 'add_meta_boxes', 'my_custom_meta_box' ) );
function my_custom_meta_box(){
$args = array();
add_meta_box(
'my_metabox_id',
__( 'My Meta Box', 'my_textdomain' ), // Title
'my_callback_function', // Callback function that renders the content of the meta box
'post', // Admin page (or post type) to show the meta box on
'side', // Context where the box is shown on the page
'high', // Priority within that context
$args // Arguments to pass the callback function, if any
);
}
function my_callback_function( $args ){
//The markup for your meta box goes here
}https://stackoverflow.com/questions/55738074
复制相似问题