gpt4 book ai didi

javascript - WordPress 自定义字段单选按钮无法选中

转载 作者:行者123 更新时间:2023-12-03 05:51:09 25 4
gpt4 key购买 nike

我一直在尝试在我的领域制作单选按钮,如下所示:

function orderMB_meta_box_output( $post ) {
// create a nonce field
wp_nonce_field( 'my_orderMB_meta_box_nonce', 'orderMB_meta_box_nonce' ); ?>
<p>
<label><b>Status Order :</b></label>
<br />
<input type="radio" name="status_order" value="Process Packing" <?php echo ($value[0] == 'Process Packing')? 'checked="checked"':''; ?> >Process Packing<br>
<input type="radio" name="status_order" value="Shipping" <?php echo ($value[0] == 'Shipping')? 'checked="checked"':''; ?> >Shipping<br>
<input type="radio" name="status_order" value="Arrive" <?php echo ($value[0] == 'Arrive')? 'checked="checked"':''; ?> >Arrive<br>
<input type="radio" name="status_order" value="Success" <?php echo ($value[0] == 'Success')? 'checked="checked"':''; ?> >Success<br>
</p>
<?php
}

function orderMB_meta_box_save( $post_id ) {
// Stop the script when doing autosave
if( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return;

// Verify the nonce. If insn't there, stop the script
if( !isset( $_POST['orderMB_meta_box_nonce'] ) || !wp_verify_nonce( $_POST['orderMB_meta_box_nonce'], 'my_orderMB_meta_box_nonce' ) ) return;

// Stop the script if the user does not have edit permissions
if( !current_user_can( 'edit_post' ) ) return;
update_post_meta( $post_id, 'orderno', esc_attr( $_POST['orderno'] ) );
$allowed = array('Process Packing','Shipping','Arrive','Success');

if( isset( $_POST['status_order'] ) && in_array($_POST['status_order'], $allowed))
update_post_meta( $post_id, 'status_order', esc_attr( $_POST['status_order'] ) );
}
add_action( 'save_post', 'orderMB_meta_box_save' );

我认为我的代码是正确的并且可以工作,但是为什么我的单选按钮不会被检查。

有人帮我吗?

最佳答案

您错过了从针对当前帖子 ID 存储的数据库中获取值的行。

$status_order = get_post_meta( $post->ID, 'status_order', true );

你的函数应该有上面的行来获取值并通过var_dump()检查它。如果值完美显示/检查了您的单选按钮,请删除 var_dump。

function orderMB_meta_box_output( $post ) {
// create a nonce field
wp_nonce_field( 'my_orderMB_meta_box_nonce', 'orderMB_meta_box_nonce' );
$status_order = get_post_meta( $post->ID, 'status_order', true );
var_dump($status_order); // dump to check database value
?>
<p>
<label><b>Status Order :</b></label>
<br />
<input type="radio" name="status_order" value="Process Packing" <?php echo ($status_order == 'Process Packing')? 'checked="checked"':''; ?> >Process Packing<br>
<input type="radio" name="status_order" value="Shipping" <?php echo ($status_order == 'Shipping')? 'checked="checked"':''; ?> >Shipping<br>
<input type="radio" name="status_order" value="Arrive" <?php echo ($status_order == 'Arrive')? 'checked="checked"':''; ?> >Arrive<br>
<input type="radio" name="status_order" value="Success" <?php echo ($status_order == 'Success')? 'checked="checked"':''; ?> >Success<br>
</p>
<?php
}

关于javascript - WordPress 自定义字段单选按钮无法选中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40146463/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com