元数据库数据不更新



我有一个自定义的帖子类型,有一个自己的带有输入字段的元盒现在我添加负责保存值的代码。在这之后,我查看添加数据库,并且不保存值。

<div class="fieldGroup">
<label class="labelBlcnr">Prijs</label>
<span class="currency">&euro;</span>
<input type="text" class="price" name="item_price" id="item_price" value="<?php echo $price; ?>"/>
</div>
<div class="fieldGroup">
<label class="labelBlcnr">Intern nummer</label>
<input type="text" name="intern_sku"/>
</div>

<?php
add_action( 'save_post', function() {
global $post;
if ( array_key_exists( 'item_price', $_POST ) ) {
update_post_meta( $post->ID, '_item_price', $_POST['item_price'] );
}   
});
?>

如果我回显$post->身份证我得到了正确的身份证

希望有人能帮我

最好在代码下面使用do_action("save_post_{$post->post_type};,int$post_ID,WP_post$post,bool$update(检查。

add_action( 'save_post_your_custom_post_type', 'update_meta_box_value', 10, 3 );
function update_meta_box_value( $post_id, $post, $update ){
if( isset( $_POST['item_price'] ) && $_POST['item_price'] != '' ) {
update_post_meta( $post_id, '_item_price', $_POST['item_price'] );
}
}

最新更新