我不知道如何保存此元数据库,请帮助我。这是我的代码:
<?php
function book_function_meta_box(){
add_meta_box(\'book_meta_box\', \'more Infos\', \'book_meta_box_callback\', \'book\', \'normal\');
}
add_action(\'add_meta_box\', \'book_add_meta_box\');
function book_meta_box_callback()
{
wp_nonce_field(\'book_save_meta_box_data\', \'book_nonce_name\');
$terms = get_terms(
\'category\',
array(
\'orderby\' => \'id\',
\'hide_empty\' => 1 // hide categories with no posts
)
);
foreach ($terms as $term) {
$args = array(
\'post_type\' => \'book\',
\'category\' => $term->slug
);
$query = new WP_Query($args);
echo \'<h2 class="h2 faq-cat">\' . $term->name . \'</h2>\';
while ($query->have_posts()) : $query->the_post();
$livre_slug = sanitize_title_with_dashes(get_the_title(get_the_ID()));
$qte_slug = $livre_slug . \'qte\';
?>
<div>
<label for="<?php the_ID(); ?>">
<?php echo \'<h1>\' . the_title() . \'</h1>\'; ?>
</label>
<input type="checkbox" name="<?php echo $livre_slug; ?>" id="<?php the_ID(); ?>" value="<?php the_title(); ?>" <?php if (isset($_POST[$livre_slug])) echo \'checked="checked"\'; ?> />
<label for="<?php echo $qte_slug; ?>" style="margin-left: 352px;buttom">
<?php echo \'Qte\'; ?>
</label>
<input type="number" id="<?php the_ID(); ?>" name="<?php echo $qte_slug; ?>" style="margin-left: 452px;" value="<?php echo esc_attr(get_post_meta(get_the_ID(), $qte_slug, true)); ?>" />
</div>
<?php
wp_reset_postdata();
endwhile;
// use reset postdata to restore the original query
wp_reset_postdata();
}
}