Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have a custom meta box created using Rilwis meta box script(http://www.deluxeblogtips.com/meta-box/) inside my theme functions.php.

It has 2 text fields, one field is required to fetch results from api, so, it needs to be visible on the custom meta box. But, the other field stores a serialized array which is the response fetched from external api. So, I want to make this field hidden.

Please tell me how can I hide the other field. Here is the code which defines the two text fields:

if (!class_exists('F8_Stores')) {
    class F8_Stores {

        private $fields = array();
        private $validation = array();
        private $prefix = 'f8_';

        public function __construct() {

            add_action('admin_init', array($this, 'register_store_meta_box'));
        }

        public function register_store_meta_box() {
            $this -> fields = $this -> add_custom_fields();
            $this -> validation = $this -> add_validation_rules();

            $meta_box = array('id' => 'f8_stores', 'title' => 'Online Retail Stores', 'pages' => array('post', 'page'), 'context' => 'normal', 'priority' => 'high', 'fields' => $this -> fields, 'validation' => $this -> validation);
            new RW_Meta_Box($meta_box);

        }

        private function add_custom_fields() {
            $fields = array( array('name' => 'Amazon US Product ASIN', 'desc' => 'Please enter product ASIN', 'id' => $this -> prefix . 'amazon_us_asin', 'type' => 'text', 'std' => false, 'clone' => false, ),
             array('name' => 'Amazon US Store Cache', 'desc' => 'Users should not see this', 'id' => '_' . $this -> prefix . 'amazon_us_store_cache', 'type' => 'text', 'clone' => false, ), );
            echo $fields[1]['id'];
            return $fields;
        }

        private function add_validation_rules() {
            $validation = array();

             return $validation;
        }

    }

}
$F8_Stores = new F8_Stores();

I am using this inside a class, and despite adding '_'in front of 'id' of text field 2, the field is still visible inside metabox. Don't know what I am missing?

Any help is appreciated...thanks!

P.S. I am using Rilwis Meta Box 4.2.3 and Wordpress 3.5 running on xampp.

Update: I have now posted my actual class responsible for generating metabox. Update: Thanks everyone for response, the problem is now fixed.

share|improve this question
add comment

2 Answers

up vote 1 down vote accepted

Using a leading underscore will hide the field's value from the default WordPress Custom Fields section, not the meta box you create via the plugin.

If you don't want the field visible in your custom meta box, don't add the field to the meta box at all, it really serves no purpose there anyway. You can manage the field's value in your code directly via update_post_meta and get_post_meta.

share|improve this answer
    
You're right here @Milo. Actually no custom field is required here. –  fischi Jan 17 '13 at 17:45
    
@Milo: Thanks, and I was wondering why adding underscore in front of field id wasn't hiding it. And, thanks for suggesting, quickly removed field from the metabox, and the code is working. –  Chetan Jan 17 '13 at 17:56
add comment

You don't have to put the _ in front of 'id', but in front of the prefix.

Your code should work like that:

$fields = array(
    array(
        'name' => 'Text field 1',
        'desc' => 'This is required',
        'id' => '_' . $this -> prefix . 'field_1',
        'type' => 'text',
        'std' => false,
        'clone' => false,
    ),
    array(
        'name' => 'Text field 2',
        'desc' => 'This is required',
        'id' => '_' . $this -> prefix . 'Text field 2',
        'type' => 'text',
        'clone' => false,
    ),
);
share|improve this answer
    
Its not working, I had already tried this. –  Chetan Jan 17 '13 at 17:16
    
Can you tell me how the id field is now declared in your metabox? –  fischi Jan 17 '13 at 17:17
    
@Chetan - edit your question to show where you set prefix with leading underscore. –  Milo Jan 17 '13 at 17:22
    
@Milo: I have updated the code. –  Chetan Jan 17 '13 at 17:25
    
@Chetan can you please tell me how your plugin outputs the ID of this input field? –  fischi Jan 17 '13 at 17:28
show 3 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.