0

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(
        array(
            'name' => 'Asking Price',
            'id' => $prefix . 'asking_price',
            'type' => 'text',
            'std' => ''
        ),
        array(
            'name' => 'Currency',
            'id' => $prefix . 'currency',
            'type' => 'text',
            'std' => 'USD'
        ),
        array(
            '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.

2 Answers 2

0

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

3
  • Thanks but I need post meta for metabox named "general_info" only. I have many metaboxes Dec 5, 2011 at 4:09
  • Then use get_post_meta with the key being "general_info".
    – Wyck
    Dec 5, 2011 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, 2011 at 21:52
0

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

return $metaboxes;

This will solve your problem

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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