Hi Stephan,
Thanks for the quick response.
I just found that when I remove some code, it works fine.
I also noticed that when I remove the WP_Query from that code, it works fine. Seems that it is the cause of the problem but not sure why!!!
Code below:
<?php if(is_super_admin()): ?>
<?php
function add_meta_box_vendor() {
$screens = array( 'product' );
foreach ( $screens as $screen ) {
add_meta_box(
'vendor_sectionid',
__( 'Vendor', 'vendor_textdomain' ),
'vendor_callback',
$screen,
'side'
);
}
}
add_action( 'add_meta_boxes', 'add_meta_box_vendor' );
function vendor_callback( $post ) {
wp_nonce_field( 'vendor_save_meta_box_data', 'vendor_nonce' );
$value = get_post_meta( $post->ID, '_vendor_value_key', true );
?>
<label for="vendor_field"></label>
<?php
$args = array(
'post_type' => 'my_vendor'
);
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
?>
<input type="radio" name="vendor_field" value="<?php echo $loop->post->ID; ?>" <?php if($loop->post->ID == $value){echo 'checked';} ?> /> <?php echo get_the_title($loop->post->ID); ?><br />
<?php
endwhile;
wp_reset_query();
?>
<?php
}
function vendor_save_meta_box_data( $post_id ) {
if ( ! isset( $_POST['vendor_nonce'] ) ) {
return;
}
if ( ! wp_verify_nonce( $_POST['vendor_nonce'], 'vendor_save_meta_box_data' ) ) {
return;
}
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
return;
}
if ( isset( $_POST['post_type'] ) && 'page' == $_POST['post_type'] ) {
if ( ! current_user_can( 'edit_page', $post_id ) ) {
return;
}
} else {
if ( ! current_user_can( 'edit_post', $post_id ) ) {
return;
}
}
if ( ! isset( $_POST['vendor_field'] ) ) {
return;
}
$str = $_POST['vendor_field'];
$my_data = sanitize_text_field( $str );
update_post_meta( $post_id, '_vendor_value_key', $my_data );
}
add_action( 'save_post', 'vendor_save_meta_box_data' );
?>
<?php endif; ?>