首页 > 解决方案 > 我想添加元框,但它没有显示

问题描述

我正在尝试显示一个元框,该框输入来自 Woocommerce 产品的产品代码并将其显示到页面上。出于这个原因,我正在尝试添加具有此功能的元框。但元框未显示在自定义帖子类型中。

这些是我的代码:

add_action('init', 'add_gng_offer');

function add_gng_offer() {
    $labels = array(
        'name' => 'GnG Offer',
        'singular_name' => 'GnG Offer',
        'add_new' => 'Add New Offer',
        'add_new_item' => 'Add new Offer',
        'edit_item' => 'Edit Offer',
        'new_item' => 'Add New Offer',
        'view_items' => 'View Offers',
        'search_items' => 'Search Offers',
        'not_found' => 'No Offers Found',
        'not_found_trash' => 'No Offers Found In Trash',
    );

    $supports = array(
        'title',
        'editor',
        'thumbnail',
        'comments',
        'revisions'
    );

    $args = array(
        'labels' => $labels,
        'supports' => $supports,
        'public' => true,
        'capablity_type' => 'post',
        'rewrite' => array('slug' => 'GnG Offers'),
        'has_archive' => true,
        'menu_position' => 6,
        'menu_icon' => 'dashicons-calendar-alt',
        'register_meta_box' => '',
    );

    register_post_type('GnG Offers', $args);
}

//Creating meta Boxes for Custom Post Type

function product_id_meta_box () {
    add_meta_box(
        'product_id',
        'Product Field',
        'product_function_callback',
        'GnG Offer',
        'side',
        'default'
    );
}

add_action('add_meta_boxes', 'product_id_meta_box');

另一个问题是如何在我输入产品 id 的情况下实现这种功能,它会在特定页面中显示产品。

标签: phpwordpresswoocommerce

解决方案


推荐阅读