I am new with plugin development and i have one issue while updating post meta. I have to create checkbox for each user but while updating post update_post_meta is not working for all checkboxes. Values are correct but these are not updating in database. Here is my code.
add_action( 'save_post', 'cd_meta_box_save' );
function cd_meta_box_save( $post_id )
{
global $post;
$all_users = get_users();
foreach($all_users as $user){
$my_meta_box_check = "my_meta_box_check".$user->ID;
$chk = isset( $_POST[$my_meta_box_check] ) && $_POST[$my_meta_box_check] ? 'on' : 'off';
update_post_meta( $post_id, $my_meta_box_check, $chk );
}
}
This code is working for few check boxes but not for all. I will really appreciate your help because i am trying to fix this issue for many hours but nothing working.
$post_id
variable. You need to add$post_id = $post->ID;
afterglobal $post
paged
param to it to make it 100% sure it gets all users?get_users(array('number' => 10000))