title: How to set radio buttons in custom meta box checked?
body: <p>I created a custom meta box where you can choose a value from some radio buttons and save it to the post_meta table in the wordpress database. With the following code I save the value:</p>
  
  <pre><code>function save_value_of_my_custom_metabox ($post_id, $post){
      $post_id = get_the_ID();
      $new_meta_value = ( isset( $_POST['the_name_of_the_radio_buttons'] ) ? sanitize_html_class( $_POST['the_name_of_the_radio_buttons'] ) : '' );
      $meta_key = 'my_key';
      update_post_meta( $post_id, $meta_key, $new_meta_value );
  }
  </code></pre>
  
  <p>But if the post will be edited again I want the radio button with the current value to set checked. What is the best way to do that? Here is the function to display the meta box:</p>
  
  <pre><code>function my_custom_meta_box( $object, $box ) {
      $post_id=get_the_ID();
      $key='my_key';
      $the_value_that_should_be_set_to_checked=get_post_meta( $post_id, $key);
      //$the_value_that_should_be_set_to_checked[0] returns the value as string
      ?&gt;    
      &lt;label for="my_custom_metabox"&gt;&lt;?php _e( "Choose value:", 'choose_value' ); ?&gt;&lt;/label&gt;
      &lt;br /&gt;  
        &lt;input type="radio" name="the_name_of_the_radio_buttons" value="value1"&gt;Value1&lt;br&gt;
        &lt;input type="radio" name="the_name_of_the_radio_buttons" value="value2"&gt;Value2&lt;br&gt;
        &lt;input type="radio" name="the_name_of_the_radio_buttons" value="value3"&gt;Value3&lt;br&gt;
        &lt;input type="radio" name="the_name_of_the_radio_buttons" value="value4"&gt;Value4&lt;br&gt;
  
          &lt;?php
  }
  </code></pre>
  
  <p>I could write something like <code>if(isset($the_value_that_should_be_set_to_checked[0])=="value of that line") echo "checked='checked'";</code> in every line but that doesn't seem very elegant to me. Using javascript is also pretty complicated in wordpress because I would have to use the hooks, enqueue the script and just for changing the checked property with one line of javascript it's not worth it. What's the best practice for that?</p>