0

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(
        array(
                        'name' => 'something',
            'id' => $prefix . 'something',
            'desc' => 'some description',
            'type' => 'checkbox'
              ),
                 //continue with other fields
             )
           );

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

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} )
        continue;
        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".

1

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://codex.wordpress.org/Function_Reference/add_meta_box

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

0

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

  • 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 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.