I have researched many tutorials on how to create/add Custom Meta Boxes using the add_meta_box()
Wordpress function. I can not find any example where the finished Meta Box has the option for an Admin User to input both key/value pairs like Custom_Fields?
EDIT: Removed plugin link URL as not enough rep points:
I want to add this capability to my own Custom Meta Boxes and to the WebDevStudios/Custom-Metaboxes-and-Fields-for-WordPress plugin's Meta Box fields.
To clarify, I want to create a Meta Box that Admin Users can add Name and Value to - like is shown in this image taken from the WP's own Custom Fields Meta Box :
Edit 19.06.14:
My understanding of Custom Fields
was incorrect, when querying on the front end:
printf( '<pre>%s</pre>', var_export( get_post_meta($post->ID,"my_custom_filed_key"), true ) );
I see that my_custom_field_key
produces an index array:
array (
0 => 'val 1',
1 => 'val 2',
2 => 'val 3',
)
I suppose what I am trying to achieve is an associative array?
array (
'my key name 1' => 'my val 1',
'my key name 2' => 'my val 2',
'my key name 3' => 'my val 3',
)
Here is the add_meta_box
function part of my code:
function my_meta_boxes($post) {
add_meta_box(
'my_meta', // Unique ID
esc_html__( 'Reviews', 'example' ), // Title
'my_meta_box', // Callback function
'my-post', // Admin page (or post type)
'side', // Context
'default' // Priority
);
}
/* Display the post meta box. */
function my_meta_box() {
wp_nonce_field( basename( __FILE__ ), 'my_post_nonce' );
$meta = get_post_custom($post->ID);
$meta['my_meta'] = maybe_unserialize($meta['my_meta'][0]);
?>
<table style="width:100%;">
<tr style="width:100%;">
<td><textarea style="width:90%;" rows="1" name="my_meta[]"> <?php echo $meta['my_meta'][0] ?></textarea></td>
</tr>
<tr style="width:100%;">
<td><textarea style="width:90%;" rows="1" name="my_meta[]"> <?php echo $meta['my_meta'][1] ?></textarea></td>
</tr>
<tr style="width:100%;">
<td><textarea style="width:90%;" rows="1" name="my_meta[]"> <?php echo $meta['my_meta'][2] ?></textarea></td>
</tr>
</table>
<?php }
I am wondering if the add_meta_box
$callbacks_args would help me here, but I am yet to full understand it?
Thank you.