首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将Meta not添加到自定义帖子类型不起作用

将Meta not添加到自定义帖子类型不起作用
EN

Stack Overflow用户
提问于 2019-04-18 09:48:51
回答 1查看 1.1K关注 0票数 0

我已经尝试了很多方法来解决这个问题,我对编写插件还是个新手,但是我似乎不能让它工作。

我已经创建了一个自定义的帖子类型("Book"),非常好。现在,我正在尝试将meta-boxes添加到其中。我似乎无法获得正确连接彼此的代码。

我已经尝试将每个元框的插件添加到“支持”中,我已经尝试了function和add_meta_box的各种实例,以及将不同的东西放在"register_meta_box_cb“下,但我所做的似乎都不起作用。

任何帮助都是非常感谢的。

代码语言:javascript
复制
// 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' );
EN

回答 1

Stack Overflow用户

发布于 2020-05-17 04:57:49

代码语言:javascript
复制
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

}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55738074

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档