WordPress.org

Ready to get started?Download WordPress

Forums

Meta box does not appear in a custom post type. (1 post)

  1. vishnu93
    Member
    Posted 2 years ago #

    I am trying to create a custom post type for products of a company with a text box to add the price. But no matter what I try, the meta box does not show up. Could any one help me? The code I used is,

    class vp_serivce_post{
        public function __construct() {
            $this->ser_registar();
            $this->price_box();
            add_theme_support('post-thumbnails');
    //        set_post_thumbnail_size( 80, 80, true );
        }
    
        public function ser_registar(){
    
            $args = array(
                'labels' => array(
                    'name' => 'Products',
                    'singular_name' => 'Product',
                    'add_new' => 'Add New Product',
                    'add_new_item' => 'Add New Product',
                    'edit_item' => 'Edit Product',
                    'new_item' => 'New Product',
                    'all_items' => 'All Products',
                    'view_item' => 'View Product',
                    'search_items' => 'Search Products',
                    'not_found' => 'No Product Found',
                    'not_found_in_trash' => 'No Product Found in Trash',
                    'menu_name' => 'Products'
                ),
                query_var => 'products',
                rewrite => array(
                    slug => 'products/'
                ),
                'public' => true,
                //'menu_position' => 25,
                'supports' => array(
                    'title',
                    'thumbnail',
                    'editor'
                )
            );
            register_post_type('services',$args);
        }
    
        public function price_box(){
            add_action('add_meta_boxes', 'add_price_box');
    
            function add_price_box(){
                add_meta_box('price_id', 'Price', 'price_add', 'vp_price');
    
                function price_add($post){
    ?>
    <label for="vp_price">Price: </label>
    <input type="text" class="widefat" name="vp_price" id="vp_price" vlaue="<?php echo esc_attr($length); ?>" />
    <?php
                }
            }
        }
    }
    
    add_action('init', 'post_invok');
    
    function post_invok(){
        new vp_serivce_post();
    }

Topic Closed

This topic has been closed to new replies.

About this Topic