What I'm trying to accomplish:
I'm trying to use one custom field to add multiple values to the same Meta Key.
However, for each time that I submit a value, I get a duplicate, for example:
Key1 = Sweet
Key1 = Sweet
Key1 = Yay
Key1 = Yay
And what I need help with is getting this result:
Key1 = Sweet
Key1 = Yay
Here is my current code:
I tried stripping the code down to the bare essentials, as I'm in the process of trying to understand what's happening in each line of code. I removed the nonce code that's found in the codex because, once again, it looked like trivial info for the crash course I intended to put upon myself. Be nice :)
add_action( 'add_meta_boxes', 'ez_portfolio_gallery' );
function ez_portfolio_gallery() {
add_meta_box( 'ez_portfolio_gallery', 'Portfolio Gallery', 'myplugin_inner_custom_box', 'post', 'normal', 'high' );
}
function myplugin_inner_custom_box( $post ) {
//i'm using this to output my current values in addition to what I can see in the custom fields section. For debugging purposes.
$ez_portfolio_image_name = get_post_meta($post->ID, 'ez_portfolio_image', true);
$custom_fields = get_post_custom(1);
$my_custom_field = $custom_fields['ez_portfolio_image'];
if($my_custom_field != ""){
foreach ( $my_custom_field as $key => $value ){
echo $key . " => " . $value . "<br />";
}
}
?>
<label>Image URL:</label>
<input type="text" id="ez_portfolio_image" name="ez_portfolio_image" value="" size="25" />
<?php
}
add_action( 'save_post', 'myplugin_save_postdata' );
function myplugin_save_postdata() {
// Check permissions
if ( 'post' == $_POST['post_type'] ){
$ez_portfolio_image = $_POST['ez_portfolio_image'];
if($ez_portfolio_image != ""){
add_post_meta(1, 'ez_portfolio_image', $ez_portfolio_image, false);
}
}
}