我需要第二副眼睛。我不确定为什么此代码没有正确保存。基本上,我点击save,字段值就会消失。
我还有两种其他类型的帖子,使用这种结构可以很好地保存。我觉得我只是在屏幕上看了太久,错过了一些东西。:)有什么建议吗?
谢谢
纳丁
<?php
// 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
register_taxonomy(\'book_publishers\',\'tf_books\',
array(
\'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">
<ul>
<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>
</ul>
</div>
<?php
} // 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() ?>