WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm registering multiple metaboxes in my write posts panels. In functions.php:

$meta_boxes[] = array(
    'id' => 'products',
    'title' => 'Products',
    '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' => 'something',
            'id' => $prefix . 'something',
            'desc' => 'some description',
            'type' => 'checkbox'
                 //continue with other fields

//another metabox 
$meta_boxes[] = array(
    'id' => 'customers',
    'title' => 'Customers',

I'm able to get all the values of fields in a post using:

$custom_field_keys = get_post_custom_keys();
foreach ( $custom_field_keys as $key => $value ) {
    $valuet = trim($value);

    if ( '_' == $valuet{0} )
        echo $value . ":<br />";
        echo get_post_meta($post->ID, $value, true) . "<br/><br/>";

How can I get the names and values of all fields within a metabox that I specify. For example get all values of fields in metabox id "products".

share|improve this question

If I understand your question correctly, you would like to get all metadata for "products" across all posts. In other words, multiple posts have metadata with key "products" and you want to get those values. If this is correct, you should use get_post_custom_values, which is well documented in the codex: http://codex.wordpress.org/Function_Reference/get_post_custom_values.

As a side note, are you using the Meta Box API for your meta boxes. If not, you definitely should. I'd recommend taking a look at these two articles to get started with meta boxes:


http://www.wproots.com/complex-meta-boxes-in-wordpress/ (In the interest of full disclosure, I wrote this and it is completely on topic)

share|improve this answer
Thanks! I will take a look. – Vgd Dec 2 '11 at 17:39

Just use http://www.farinspace.com/wpalchemy-metabox/ and thank me later :)

share|improve this answer
Thanks! I will try it out, I have to implement a lot of custom fields. – Vgd Dec 2 '11 at 17:49

Your Answer


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.