In my functions I'm registering multiple metaboxes with custom fields. A single metabox array for instance, looks like this:

In functions.php

$meta_boxes[] = array(
    'id' => 'general_info',
    'title' => 'General Information',
    'pages' => array('post', 'page', 'link'), // multiple post types, accept custom post types
    'context' => 'normal', // normal, advanced, side (optional)
    'priority' => 'high', // high, low (optional)
    'fields' => array(
            'name' => 'Asking Price',
            'id' => $prefix . 'asking_price',
            'type' => 'text',
            'std' => ''
            'name' => 'Currency',
            'id' => $prefix . 'currency',
            'type' => 'text',
            'std' => 'USD'
            'name' => 'Salesman',
            'id' => $prefix . 'salesman',
            'type' => 'text',
            'std' => 'Your Name'

In my theme, how can get all the field names (and even values if possible) from metabox general_info ? I'm trying to retrieve data from each metabox separately.


Use get_post_custom, it will return an array of all the posts meta info. http://codex.wordpress.org/Function_Reference/get_post_custom

  • Thanks but I need post meta for metabox named "general_info" only. I have many metaboxes Dec 5 '11 at 4:09
  • Then use get_post_meta with the key being "general_info".
    – Wyck
    Dec 5 '11 at 4:52
  • that will give me the key for the meta value not all the fields in the array. I'm having trouble finding a solution for this. Maybe I'm not explaining right Dec 7 '11 at 21:52

you have to return metabox. place the below code at the end

return $metaboxes;

This will solve your problem

  • And why would this work? Please explain your suggestion. And BTW, it's $meta_boxes.
    – tfrommen
    Feb 24 '14 at 10:18
  • We need to return an array to retrieve data from metabox, which u saved as an array. Mar 1 '14 at 6:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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