为什么在WordPress的“添加新用户界面”中不显示元框? [英] Why is meta box not appearing in WordPress Add New UI?

查看:101
本文介绍了为什么在WordPress的“添加新用户界面”中不显示元框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的代码如下(我正在处理此tuts +教程):

My code is as follows (I'm working off this tuts+ tutorial):

<?php
/**
* Plugin Name: Sermon Manager Plus
* Plugin URI: #
* Version: 0.1
* Author: Dave Mackey
* Author URI: http://www.davemackey.net/
* Description: A robust system for sermon management.
* License: GPL2
*/
?>
<?php
  class SermonManagerPlus {

  /**
   * Constructor: Called when plugin is initialized.
   */
   function __construct() {
    add_action( 'init', array( $this, 'register_custom_post_type' ) );   
    add_action( 'add_meta_boxes', array( $this, 'register_meta_boxes' ) );
   }

  /**
 * Registers a Custom Post Type called series
 */
  function register_custom_post_type() {
     register_post_type( 'contact', array(
      'labels' => array(
          'name'        => _x( 'Series', 'post type general name', 'sermon-manager-plus' ), // Plural name of CPT
          'singular_name' => _x( 'Series', 'post type singular name', 'sermon-manager-plus' ), // Singular name of CPT
          'menu_name' => _x( 'Sermons', 'admin menu', 'sermon-manager-plus' ), // Name that appears on the admin menu.
          'name_admin_bar' => _x( 'Series', 'sermon-manager-plus'),  // Name that appears on top fixed admin menu under new.
          'add_new' => _x( 'Add New', 'series', 'sermon-manager-plus'), // Add in admin menu under menu_name.
          'add_new_item' => __( 'Add New Series', 'sermon-manager-plus'),
          'new_item' => __( 'New Series', 'sermon-manager-plus'),
          'edit_item' => __( 'Edit Series', 'sermon-manager-plus'),
          'view_item' => __( 'View Series', 'sermon-manager-plus'),
          'all_items' => __( 'All Series', 'sermon-manager-plus'),
          'search_items' => __( 'Search Series', 'sermon-manager-plus'),
          'parent_item_colon' => __( 'Parent Series:', 'sermon-manager-plus'), // Only used with hierarchical CPT.
          'not_found' => __( 'No Series Found.', 'sermon-manager-plus'),
          'not_found_in_trash' => __('No Series Found in Trash.', 'sermon-manager-plus'),
          ),

          // Frontend
          'has_archive' => false, // Specific archive template?
          'public'  => false, // Can be seen by public?
          'public_queryable' => false, // Queryable by public?

          // Admin
          'capability_type' => 'post', // Use permissions as those used for post.
          'menu_icon' => 'dashicons-info', // See developer.wordpress.org/resource/dashicons/
          'menu_position' => 10,  // Appears below this menu item at the given value: 5 (posts), 10 (media), 15 (links), 20 (pages), 25 (comments)
          // 60 (first separator), 65 (plugins), 70 (users), 75 (tools), 80 (settings), 100 (second separator)
          'query_var' => true, // Query variable is set to post type.
          'show_in_menu' => true, // can be false (don't show), true (show top-level), or a string like 'tools.php' or 'edit.php?post_type="page"', e.g. if you want
          // to nest this CPT under another CPT, for example Sermons nested under Series.
          'show_ui' => true, // Generates a default UI for managing post type in admin.
          'supports' => array( // Options: title, editor, author, thumbnail, excerpt, trackbacks, custom-fields, comments, revisions, page-attributes, post-formats
              'title',
              'author',
              'comments'
              ),
              ) );
}
/**
 * Registers a Meta Box on our Series Custom Post Type, called 'Summary'
 */
function register_meta_boxes() {
    // See: https://codex.wordpress.org/Function_Reference/add_meta_box
    add_meta_box( 'series-summary', 'Series Summary', array( $this, 'output_meta_box' ), 'series', 'normal', 'high'); // $id, $title, $callback, $screen, $context, $priority
}
/**
 * Output a Series Summary meta box
 * 
 * @param WP_Post $post WordPress Post object
 */
 function output_meta_box ( $post ) {
     // Output label and field
     echo ( '<label for="series_summary">' . __( 'Summary', 'sermon-manager-plus' ) . '</label>' );
     echo ( '<input type="text" name="series_summary" id="series_summary" value="' . esc_attr( $email ) . '" />' );
 }
}


$SermonManagerPlus = new SermonManagerPlus; // Create an object of type SermonManagerPlus.
?>

我已经将其与tu​​ts +教程进行了数次比较,而我一生都看不到我在做什么错...帮助!

I've compared it several times to the tuts+ tutorial and for the life of me can't see what I'm doing wrong...Help!

推荐答案

替换此行:

add_meta_box( 
    'series-summary', 
    'Series Summary', 
    array( $this, 'output_meta_box' ), 
    'series', // <-- Problem here!
    'normal', 
    'high'
); // $id, $title, $callback, $screen, $context, $priority

add_meta_box( 
    'series-summary', 
    'Series Summary', 
    array( $this, 'output_meta_box' ), 
    'contact',  //<-- Match it with the post type 
    'normal', 
    'high'
); // $id, $title, $callback, $screen, $context, $priority

$ screen 与自定义帖子类型 contact 匹配。

where we match the $screen with the custom post type contact.

或者替换为:

 register_post_type( 'contact', array(

其中:

 register_post_type( 'series', array(

这篇关于为什么在WordPress的“添加新用户界面”中不显示元框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆