I have created a metabox which dropsdown my all users. When my post is published after selecting any one of the user the username should get updated in wp_options table. i have written the code for it but wp_options table is not getting updated.Please Help
here is my code:

function my_meta()
{
  add_meta_box(
       'my_custom_meta',
       'Created By',
       'my_meta_box_mes',
       'post',
       'normal',
       'low'
    );
}
add_action('add_meta_boxes','my_meta');

function my_meta_box_mes()

{
 if($_POST['my_custom_meta']){
    update_option( 'username', $_POST['my_custom_meta']);
  }

?>

<select name="my_custom_meta" id="my_custom_meta">

<?php
$result=get_users();
foreach ($result as $row){
  $username=$row->user_login;
?>

<option value = "<?php echo $row->ID;?>" <?php echo ($row->ID==get_option('username'))?"selected
":"";?>>
<?php echo $username?>
</option>

<?php
}
?>
</select>
<?php
}
?>

Read more here: How to update values in Wp_options table


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: