Get/Print keys/values from specific meta_box (custom fields)
-
Hi all, bare with me! I am trying to get or “print” keys (or values?) from a specific meta_box (the “field” name, id, options, etc.). The theme I am using has individual meta box files for each post type. For example: post-meta.php, page-meta.php, directory-meta.php, etc.), each contain their own functions and callbacks within each file.
Heres what I have used in the past:
print_r($meta_box['fields'][1]['name']);' That will print "Header Image" from my following meta box code:
$meta_box = array(
‘id’ => ‘metabox-directory’,
‘title’ => __(‘Custom settings for “Directory”‘),
‘description’ => __(‘Fill in this listing\’s details below..’),
‘post_type’ => ‘directory’,
‘context’ => ‘normal’,
‘priority’ => ‘high’,
‘fields’ => array(
array(
‘name’ => __(‘Header Image’),
‘desc’ => __(‘The image should be no less than 1400-2000px wide’),
‘id’ => ‘header_bg’,
‘type’ => ‘file’,
‘std’ => ”
),
)
);`<strong><em>How would I adapt that code to print the values or “keys” (not sure of terminology) from specific meta box functions (see below):</em></strong>
<?php add_action('add_meta_boxes', 'metabox_directory'); function metabox_directory(){ $meta_box = array( 'id' => 'metabox-directory', 'title' => __('Custom settings for "Directory"'), 'description' => __('Fill in this listing\'s details below..'), 'post_type' => 'directory', 'context' => 'normal', 'priority' => 'high', 'fields' => array( array( 'name' => __('Header Image'), 'desc' => __('The image should be no less than 1400-2000px wide'), 'id' => 'header_bg', 'type' => 'file', 'std' => '' ), array( 'name' => __('Listing Address'), 'desc' => __('What is this listing\'s address?'), 'id' => 'directory_address', 'type' => 'text', 'std' => '' ) ) ); $callback = create_function( '$post,$meta_box', 'create_meta_box( $post, $meta_box["args"] );' ); add_meta_box( $meta_box['id'], $meta_box['title'], $callback, $meta_box['post_type'], $meta_box['context'], $meta_box['priority'], $meta_box ); } ?>
I am trying to do all this in order to determine how to filter posts based on their meta-data..
Any and all help/suggestions is truly appreciated – clearly I am a bit of a noob with this stuff but trying to learn! Thanks in advance!!
- The topic ‘Get/Print keys/values from specific meta_box (custom fields)’ is closed to new replies.