Support » Plugin: Meta Box - WordPress Custom Fields Framework » Metaboxes not showing in custom post type…Please help?!?!?!?!?!?!?!?!?!?!?!?!?

  • I am having the hardest time with getting the metaboxes to show up in my custom post type “Add New”. I’ve created a very rustic plugin for it. I have no idea what I am doing. Please help me with my code.

    <?php
    /*
    /**
    * Plugin Name: Brand Boxes
    * Description: A custom display box for current items/brands.
    * Version: 1
    * Author: Jafi
    **/
    /* Start Adding Functions Below this Line */
    
    add_filter( 'rwmb_meta_boxes', 'brandsboxes_register_meta_boxes' );
    
    /* Variables */
    $ja_brand_boxes_main_file = dirname(__FILE__).'/brand-box.php';
    $ja_brand_boxes_directory = plugin_dir_url($ja_brand_boxes_main_file);
    $ja_brand_boxes_path = dirname(__FILE__);
    
    ////////////////////////////////////////////////////////////////////////////////////////////
    //////////////////////       WP Default Functionality       ////////////////////////////////
    ////////////////////////////////////////////////////////////////////////////////////////////
    add_theme_support( 'post-thumbnails' );
    
    /*
    * Creating a function to create our CPT
    */
    add_action('init', 'create_brandsboxes');
    
    function create_brandsboxes() {
    
    // Set UI labels for Custom Post Type
    	$labels = array(
    		'name'                => _x( 'Brands', 'Post Type General Name', 'brand8box' ),
    		'singular_name'       => _x( 'Brand', 'Post Type Singular Name', 'brand8box' ),
    		'menu_name'           => __( 'Brands', 'brand8box' ),
    		'parent_item_colon'   => __( 'Parent Brand', 'brand8box' ),
    		'all_items'           => __( 'All Brands', 'brand8box' ),
    		'view_item'           => __( 'View Brand', 'brand8box' ),
    		'add_new_item'        => __( 'Add New Brand', 'brand8box' ),
    		'add_new'             => __( 'Add New', 'brand8box' ),
    		'edit_item'           => __( 'Edit Brand', 'brand8box' ),
    		'update_item'         => __( 'Update Brand', 'brand8box' ),
    		'search_items'        => __( 'Search Brand', 'brand8box' ),
    		'not_found'           => __( 'Not Found', 'brand8box' ),
    		'not_found_in_trash'  => __( 'Not found in Trash', 'brand8box' ),
    	);
    
    // Set other options for Custom Post Type
    
    	$brandsboxes_args = array(
    		'label'               => __( 'brandsboxes', 'brand8box' ),
    		'description'         => __( 'Brands we carry', 'brand8box' ),
    		'labels'              => $labels,
    		// Features this CPT supports in Post Editor
    		'supports'            => array( 'title', 'editor', 'excerpt', 'thumbnail', 'revisions', 'custom-fields', 'trackbacks' ),
    		// You can associate this CPT with a taxonomy or custom taxonomy.
    		'taxonomies'          => array( 'type' ),
    		/* A hierarchical CPT is like Pages and can have
    		* Parent and child items. A non-hierarchical CPT
    		* is like Posts.
    		*/
    		'hierarchical'        => false,
    		'public'              => true,
    		'show_ui'             => true,
    		'show_in_menu'        => true,
    		'show_in_nav_menus'   => true,
    		'show_in_admin_bar'   => true,
    		'menu_position'       => 4,
    		'menu_icon' 		  => 'dashicons-archive',
    		'can_export'          => true,
    		'has_archive'         => true,
    		'exclude_from_search' => false,
    		'publicly_queryable'  => true,
    		'capability_type'     => 'page',
    	);
    
    	// Registering your Custom Post Type
    	register_post_type( 'brandsboxes', $brandsboxes_args );
    
    }
    
    add_filter( 'rwmb_meta_boxes', 'brandsboxes_register_meta_boxes' );
    
    /**
     * Register meta boxes
     *
     * Remember to change "your_prefix" to actual prefix in your project
     *
     * @param array $meta_boxes List of meta boxes
     *
     * @return array
     */
    function brandsboxes_register_meta_boxes( $meta_boxes )
    {
    	/**
    	 * prefix of meta keys (optional)
    	 * Use underscore (_) at the beginning to make keys hidden
    	 * Alt.: You also can make prefix empty to disable it
    	 */
    	// Better has an underscore as last sign
    	$prefix = 'brand8box';
    
    	// 1st meta box
    	$meta_boxes[] = array(
    		// Meta box id, UNIQUE per meta box. Optional since 4.1.5
    		'id'         => 'standard',
    
    		// Meta box title - Will appear at the drag and drop handle bar. Required.
    		'title'      => __( 'Standard Fields', 'brand8box' ),
    
    		// Post types, accept custom post types as well - DEFAULT is 'post'. Can be array (multiple post types) or string (1 post type). Optional.
    		'post_types' => array( 'brandsboxes' ),
    
    		'pages'    => array( 'post', 'brandsboxes' ),
    
    		// Where the meta box appear: normal (default), advanced, side. Optional.
    		'context'    => 'normal',
    
    		// Order of meta box: high (default), low. Optional.
    		'priority'   => 'high',
    
    		// Auto save: true, false (default). Optional.
    		'autosave'   => true,
    
    		// List of meta fields
    		'fields'     => array(
    			// TEXT
    			array(
    				// Field name - Will be used as label
    				'name'  => __( 'Text', 'brand8box' ),
    				// Field ID, i.e. the meta key
    				'id'    => "{$prefix}text",
    				// Field description (optional)
    				'desc'  => __( 'Text description', 'brand8box' ),
    				'type'  => 'text',
    				// Default value (optional)
    				'std'   => __( 'Default text value', 'brand8box' ),
    				// CLONES: Add to make the field cloneable (i.e. have multiple value)
    				'clone' => true,
    			),
    
    			// TEXTAREA
    			array(
    				'name' => __( 'Textarea', 'brand8box' ),
    				'desc' => __( 'Textarea description', 'brand8box' ),
    				'id'   => "{$prefix}textarea",
    				'type' => 'textarea',
    				'cols' => 20,
    				'rows' => 3,
    			),
    		),
    	);
    
    	// 2nd meta box
    	$meta_boxes[] = array(
    		'title'  => __( 'Advanced Fields', 'brand8box' ),
    		'pages'    => array( 'post', 'brandsboxes' ),
    		'post_types' => array( 'post', 'page', 'brandsboxes' ),
    
    		'fields' => array(
    			// HEADING
    			array(
    				'type' => 'heading',
    				'name' => __( 'Heading', 'brand8box' ),
    				'id'   => 'fake_id', // Not used but needed for plugin
    				'desc' => __( 'Optional description for this heading', 'brand8box' ),
    			),
    			// SLIDER
    			array(
    				'name'       => __( 'Slider', 'brand8box' ),
    				'id'         => "{$prefix}slider",
    				'type'       => 'slider',
    
    				// jQuery UI slider options. See here http://api.jqueryui.com/slider/
    				'js_options' => array(
    					'min'  => 10,
    					'max'  => 255,
    					'step' => 5,
    				),
    			),
    
    			// CHECKBOX LIST
    			array(
    				'name'    => __( 'Checkbox list', 'brand8box' ),
    				'id'      => "{$prefix}checkbox_list",
    				'type'    => 'checkbox_list',
    				// Options of checkboxes, in format 'value' => 'Label'
    				'options' => array(
    					'value1' => __( 'Label1', 'brand8box' ),
    					'value2' => __( 'Label2', 'brand8box' ),
    				),
    			),
    			// URL
    			array(
    				'name' => __( 'URL', 'brand8box' ),
    				'id'   => "{$prefix}url",
    				'desc' => __( 'URL description', 'brand8box' ),
    				'type' => 'url',
    				'std'  => 'http://google.com',
    			),
    
    			// TAXONOMY
    			array(
    				'name'    => __( 'Taxonomy', 'brand8box' ),
    				'id'      => "{$prefix}taxonomy",
    				'type'    => 'taxonomy',
    				'options' => array(
    					// Taxonomy name
    					'taxonomy' => 'category',
    					// How to show taxonomy: 'checkbox_list' (default) or 'checkbox_tree', 'select_tree', select_advanced or 'select'. Optional
    					'type'     => 'checkbox_list',
    					// Additional arguments for get_terms() function. Optional
    					'args'     => array()
    				),
    			),
    			// POST
    			array(
    				'name'        => __( 'Posts (Pages)', 'brand8box' ),
    				'id'          => "{$prefix}pages",
    				'type'        => 'post',
    				// Post type
    				'post_type'   => 'page',
    				// Field type, either 'select' or 'select_advanced' (default)
    				'field_type'  => 'select_advanced',
    				'placeholder' => __( 'Select an Item', 'brand8box' ),
    				// Query arguments (optional). No settings means get all published posts
    				'query_args'  => array(
    					'post_status'    => 'publish',
    					'posts_per_page' => - 1,
    				)
    			),
    
    			// IMAGE UPLOAD
    			array(
    				'name' => __( 'Image Upload', 'brand8box' ),
    				'id'   => "{$prefix}image",
    				'type' => 'image',
    			),
    			// BUTTON
    			array(
    				'id'   => "{$prefix}button",
    				'type' => 'button',
    				'name' => ' ', // Empty name will "align" the button to all field inputs
    			),
    		)
    	);
    
    	return $brandfields;
    
    	$brand_box = new brandsboxes_add_meta_box( 'brandboxes_box', __('Brand Info', 'brand8box'), $brandfields, 'brandsboxes', true );
    }
    
    /* Hook into the 'init' action so that the function
    * Containing our post type registration is not
    * unnecessarily executed.
    */
    
    add_action( 'init', 'custom_post_type', 0 );
    
    /* Stop Adding Functions Below this Line */
    ?>

    https://wordpress.org/plugins/meta-box/

  • The topic ‘Metaboxes not showing in custom post type…Please help?!?!?!?!?!?!?!?!?!?!?!?!?’ is closed to new replies.