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 have a custom meta box on a custom post-type.

I've followed this tutorial but can't get the value I enter to save, I'm guessing I've referenced to something incorrectly. I've looked at the other answers here but no one seems to be using the same save method as I am, and I'm unsure of how to use those answers. This is how I'm creating the fields in the meta box:

// Album Information Metabox Content
function meta_album_info() {
    global $post;
    // Noncename needed to verify where the data originated
    echo '<input type="hidden" name="albummeta_noncename" id="albummeta_noncename" value="' .
    wp_create_nonce( plugin_basename(__FILE__) ) . '" />';
    $year_released = get_post_meta($post->ID, '_year_released', true);
    $record_label = get_post_meta($post->ID, '_record_label', true);
    echo '<p>Year Released<br /><input type="text" name="_year_released" value="' . $year_released  . '" class="widefat" placeholder="1980" /></p>
    <p>Label<br /><input type="text" name="_record_label" value="' . $record_label  . '" class="widefat" placeholder="2Tone" /></p>';

And here's how I'm attempting to save the data (well for now just the year_released field):

// save album info
function wpt_save_album_meta($post_id, $post) {
    if ( !wp_verify_nonce( $_POST['albummeta_noncename'], plugin_basename(__FILE__) )) {
    return $post->ID;
    if ( !current_user_can( 'edit_post', $post->ID ))
        return $post->ID;
    $album_meta['_year_released'] = $_POST['_year_released'];
    foreach ($album_meta as $key => $value) {
        if( $post->post_type == 'revision' ) return;
        $value = implode(',', (array)$value);
        if(get_post_meta($post->ID, $key, FALSE)) {
            update_post_meta($post->ID, $key, $value);
        } else {
            add_post_meta($post->ID, $key, $value);
        if(!$value) delete_post_meta($post->ID, $key);
add_action('save_post', 'wpt_save_album_meta', 1, 1);

much appreciated!

share|improve this question
Are you using this code in a plugin? – Pieter Goosen May 1 '14 at 13:13
Nope, it's all in functions.php, should I be? – Brad Adams May 1 '14 at 13:16
@PieterGoosen ah, sorry didn't understand question. I'm using it for a theme, and as I said, in the functions.phpfile. – Brad Adams May 1 '14 at 13:57
Looks like you'd only be saving one value-- _year_released-- at best. Please narrow this down. Exactly where does the code fail? – s_ha_dum May 1 '14 at 14:10
@s_ha_dum Yes, that's the only value I've been trying to save up to now (will attempt to save other value once I can get this one sorted). When I select update/publish and the page reloads, the field is empty. – Brad Adams May 1 '14 at 15:14

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.