未显示自定义类型的元框

时间:2016-12-27 作者:mahesh kumar

这是我的自定义类型邮编。我想在那里添加元框。。。

function events_cust(){
      $label = array(
            \'name\' => _x(\'Events\'),
            \'singular_name\' => _x(\'events\'),
            \'menu_name\'  => __(\'Events\'),
            \'add_new\' => __(\'Add Event\'),
            \'add_new_item\' => __ (\'Add New Event\'),
            \'all_item\' => __(\'All Event\'),
            \'edit_item\' => __(\'Edit Event\'),
            \'new_item\' => __(\'New Event\'),
            \'view_item\' => __(\'View Event\'),
            \'update_item\' => __(\'update Event\'),
            \'search_item\' => __(\'Search Event\')
            );
            $attr = array(
            \'label\' => __(\'Events\'),
            \'description\' => __(\'Event\'),
            \'labels\' => $label,
            \'supports\'  => array(\'title\',\'editor\',\'thumbnail\'),
            \'taxonomies\' => array(\'genres\'),
            \'hiecrarhical\' => false,
            \'public\' => true,
            \'show_ui\' => true,
            \'show_in_menu\' => true,
            \'show_in_adim_bar\' => true,
            \'menu_position\'       => 5,
   \'can_export\'          => true,
   \'has_archive\'         => true,
   \'exclude_from_search\' => false,
   \'publicly_queryable\'  => true,
   \'capability_type\'     => \'post\',
            );
            register_post_type(\'events-lists\',$attr);
      }
      add_action( \'init\', \'events_cust\', 0 );

   add_action(\'add_meta_boxes\',\'create_events_metaboxes\');
   function create_events_metaboxes(){
      add_meta_box(\'events-meta-box\',\'Events Details\',\'show_events_metaboxes\',\'events-lists\',\'normal\',\'hight\');
   }

   function show_events_metaboxes(){
    echo \'Hello Meta box\';
   }
我们怎么了。

3 个回复
SO网友:AddWeb Solution Pvt Ltd

尝试以下代码。

add_action(\'add_meta_boxes\',\'create_events_metaboxes\'); 
function create_events_metaboxes() { 
  add_meta_box(\'events-meta-box\',\'Events Details\',\'show_events_metaboxes\',\'events-lists\'); 
}

function show_events_metaboxes($post){ echo \'Hello Meta box\'; }
希望这对你有帮助。

参考自add_meta_box

SO网友:Third Essential Designer

ACF 可能对你的进一步跑步有帮助。如果您需要更有条理的元框,请尝试。

SO网友:B.M.Rafiul Alam

尝试以下操作:

    function event_custom_meta_boxes( $post_type, $post ) {
        add_meta_box( 
            \'my-meta-box\',
            __( \'My Meta Box\' ),
            \'render_my_meta_box\',
            \'post\', //post type, event, product etc. 
            \'normal\',
            \'default\'
        );
    }
    add_action( \'add_meta_boxes\', \'event_custom_meta_boxes\', 10, 2 );

  function render_my_meta_box(){
    echo "Hello World!";
  }
更多参考:https://codex.wordpress.org/Plugin_API/Action_Reference/add_meta_boxes

相关推荐