0

I need a second set of eyes, because its late and I can't see this anymore.

Why won't this save? What am I missing?

add_action("admin_menu", "tf_book_stuff_create");

function tf_book_stuff_create(){
    add_meta_box('tf_book_stuff', 'Book Stuff', 'tf_book_stuff', 'books');
}

function tf_book_stuff() {
    global $post;
    $custom = get_post_custom($post->ID);
    $tf_book_number = $custom["tf_book_number"][0];
    $tf_book_reader = $custom["tf_book_reader"][0];

    echo $tf_book_isbn;
    echo $tf_book_level;

?>  

    <div class="admin_meta"> 
    <ul>
        <li><label>Book ISBN:</label><input name="tf_book_number" value="<?php echo $tf_book_number; ?>" /></li>
        <li><label>Reading Level:</label><input name="tf_book_reader" value="<?php echo $tf_book_reader; ?>" /></li>
    </ul>
    </div>
<?php }



add_action("admin_menu", "save_tf_book_stuff");
function save_tf_book_stuff($post_id) {
    global $post;

    update_post_meta($post->ID, "tf_book_number", $_POST["tf_book_number"]);
    update_post_meta($post->ID, "tf_book_reader", $_POST["tf_book_reader"]);
}

Thanks

3
  • Isn't this a duplicate of wordpress.stackexchange.com/questions/65000/… ? Are you having further problems? Sep 13, 2012 at 20:33
  • Kind of different, same vein. I usually have meta-box issues of some kind. Mostly I just forget something. In this case, one line.
    – Nadine
    Sep 13, 2012 at 21:30
  • Ok, but the code I provided there should have been saving properly. As I posted on your other question, $post_id is passed as a parameter to your save_tf_book_stuff($post_id) function. Sep 13, 2012 at 21:38

2 Answers 2

0

Instead of using the global $post variable, try just using the $post_id that was passed to the function in the first place.

update_post_meta($post_id "tf_book_number", $_POST["tf_book_number"]);
update_post_meta($post_id, "tf_book_reader", $_POST["tf_book_reader"]);
3
  • Hmm. That didn't work. Maybe there's another way to code said meta box.
    – Nadine
    Sep 13, 2012 at 17:50
  • I'm sorry, I don't see anything wrong with your code. Sep 13, 2012 at 18:08
  • S'okay, found a solution. Thank you for the response though.
    – Nadine
    Sep 13, 2012 at 21:23
0

Oh I found it. Its probably a little backwards (ie I'm sure there are shorter nicer ways to do it), but it works.

function save_tf_book_stuff() {
global $post;
$custom = get_post_custom($post->ID);
update_post_meta($post->ID, "tf_book_number", $_POST["tf_book_number"]);
update_post_meta($post->ID, "tf_book_reader", $_POST["tf_book_reader"]);

}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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