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 need a second set of eyes. I am unsure why this code is not saving properly. Basically I hit save and my field values disappear.

I have two other post-types saving fine using this structure. I feel I've just been looking at a screen too long and am missing something. :) Any suggestions?



// adding a custom post type for books 
add_action('init', 'books_register');

function books_register() {

    $labels = array(
        'name' => _x('Books', 'post type general name'),
        'singular_name' => _x('Book', 'post type singular name'),
        'add_new' => _x('Add New', 'Book'),
        'add_new_item' => __('Add New Book'),
        'edit_item' => __('Edit Book'),
        'new_item' => __('New Book'),
        'view_item' => __('View Book'),
        'search_items' => __('Search Books'),
        'not_found' =>  __('No Books found'),
        'not_found_in_trash' => __('No Books found in Trash'),
        //'has_archive' => true,
        'parent_item_colon' => ''


    $args = array(
        'labels' => $labels,
        'public' => true,
        'publicly_queryable' => true,
        'show_ui' => true,
        'query_var' => true,
        'rewrite' => true,
        'capability_type' => 'post',
        'hierarchical' => false,
        'menu_position' => null,
        'supports' => array('title','editor','author','excerpt','thumbnail'),
        'taxonomies' => array('book_publisher','post_tag'),


    register_post_type( 'tf_books' , $args );

    // make some taxonomies

            'hierarchical' => true,
            'label' => 'Book Publisher',
            'query_var' => true,
            'rewrite' => true

    add_action("admin_init", "tf_book_deets_create");

        function tf_book_deets_create(){
            // this is for sorting the post
            add_meta_box('tf_book_details', 'Book Details', 'tf_book_details', 'tf_books');

        // values and output (or where it ALWAYS FUCKS UP)

        function tf_book_details () {
            global $post;

            $custom = get_post_custom($post->ID);

            $article_date = $custom["tf_book_author"][0];
            $article_date = $custom["tf_book_afirst"][0];
            $article_date = $custom["tf_book_isbn"][0];
            $article_date = $custom["tf_book_dts"][0];
            $article_date = $custom["tf_book_price"][0];


            <div class="admin_meta"> 
                    <li><label>Author Last Name:</label><input name="tf_book_author" value="<?php echo $tf_book_author; ?>" /></li>
                    <li><label>Author First Name:</label><input name="tf_book_afirst" value="<?php echo $tf_book_afirst; ?>" /></li>
                    <li><label>Book ISBN:</label><input name="tf_book_isbn" value="<?php echo $tf_book_isbn; ?>" /></li>
                    <li><label>Book Details:</label><input name="tf_book_dts" value="<?php echo $tf_book_dts; ?>" /></li>
                    <li><label>Book Price:</label><input name="tf_book_price" value="<?php echo $tf_book_price; ?>" /></li> 

        } // end of book details

        // save this shit

        add_action ('save_post', 'save_book_details');  

        function save_tf_book_details(){ 
        global $post;

        update_post_meta($post->ID, "tf_book_author", $_POST["tf_book_author"]);    
        update_post_meta($post->ID, "tf_book_afirst", $_POST["tf_book_afirst"]);
        update_post_meta($post->ID, "tf_book_isbn", $_POST["tf_book_isbn"]);
        update_post_meta($post->ID, "tf_book_dts", $_POST["tf_book_dts"]);  
        update_post_meta($post->ID, "tf_book_price", $_POST["tf_book_price"]);


} // end of book_deets_create() ?>
share|improve this question
up vote 1 down vote accepted
$article_date = $custom["tf_book_author"][0];
$article_date = $custom["tf_book_afirst"][0];
$article_date = $custom["tf_book_isbn"][0];
$article_date = $custom["tf_book_dts"][0];
$article_date = $custom["tf_book_price"][0];

This is your issue. You need to set these to $tf_book_author and such, especially if you're going to echo them. I stopped there, so there may be more errors in the code, but that's the first one to knock out.

share|improve this answer
Welp, that's a sign I've been looking at too many screens to not notice something that obvious. Thanks. Changed them, but its still not updating. – Nadine Jan 29 '12 at 3:39
Found it! Didn't set up the last function right. Sorry to bother folks. proof that I should sleep. Thanks. :) – Nadine Jan 29 '12 at 3:43

Your Answer


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

Not the answer you're looking for? Browse other questions tagged or ask your own question.