WordPress.org

Ready to get started?Download WordPress

Forums

OptionTree
[resolved] why add meta boxes can't be displayed in post (2 posts)

  1. thirtyjin
    Member
    Posted 1 year ago #

    When I add the meta boxes as the Documentation said,but it can't be displayed in post;

    mytheme/includes/meta-boxes.php

    <?php
    /**
     * Initialize the meta boxes.
     */
    add_action( 'admin_init', '_custom_meta_boxes' );
    
    /**
     * Meta Boxes demo code.
     *
     * You can find all the available option types
     * in demo-theme-options.php.
     *
     * @return    void
     *
     * @access    private
     * @since     2.0
     */
    function _custom_meta_boxes() {
    
      /**
       * Create a custom meta boxes array that we pass to
       * the OptionTree Meta Box API Class.
       */
      $my_meta_box = array(
        'id'          => 'my_meta_box',
        'title'       => 'Demo Meta Box',
        'desc'        => '',
        'pages'       => array( 'post' ),
        'context'     => 'normal',
        'priority'    => 'high',
        'fields'      => array(
          array(
            'label'       => 'Background',
            'id'          => 'my_background',
            'type'        => 'background',
            'desc'        => 'BlahLorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.',
            'std'         => '',
            'rows'        => '',
            'post_type'   => '',
            'taxonomy'    => '',
            'class'       => ''
          ),
          array(
            'label'       => 'Category Checkbox',
            'id'          => 'my_category_checkbox',
            'type'        => 'category-checkbox',
            'desc'        => 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.',
            'std'         => '',
            'rows'        => '',
            'post_type'   => '',
            'taxonomy'    => '',
            'class'       => ''
          )
      	)
      );
    
      /**
       * Register our meta boxes using the
       * ot_register_meta_box() function.
       */
      ot_register_meta_box( $my_meta_box );
    
    }

    mytheme/function.php

    /**
    	 * Meta Boxes
    	 */
    	include_once( 'includes/meta-boxes.php' );

    if it work well, there are two meta boxes when new post, right? but there are no meta boxes in the post.
    who can help me?

    PS: Theme options work well.

    http://wordpress.org/extend/plugins/option-tree/

  2. thirtyjin
    Member
    Posted 1 year ago #

    I changed the actual file name from meta-boxes.php to xxxx-meta-boxes.php and the meta boxes finally showed up.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic