I am trying to make a plugin, so far everything is working, the problem is when its time to "save changes" the text are saved but the selected 2 checkbox didnt save so both remains unchecked.

Heres the screenshot, the inputed text in input type is saved so its working, but the selected 2 checkbox remained unchecked, why is this?

enter image description here

Here's my code

add_action( 'admin_init', function() {
    register_setting( 'my-awesome-plugin-settings', 'map_option_1' );
    register_setting( 'my-awesome-plugin-settings', 'map_option_2' );
    register_setting( 'my-awesome-plugin-settings', 'map_option_3' );
    register_setting( 'my-awesome-plugin-settings', 'map_option_4' );
    register_setting( 'my-awesome-plugin-settings', 'map_option_5' );
    register_setting( 'my-awesome-plugin-settings', 'map_option_6' );


    function sort_post_plugin() {
        <div class="wrap">
          <form action="options.php" method="post">
              settings_fields( 'my-awesome-plugin-settings' );
              do_settings_sections( 'my-awesome-plugin-settings' );
           <div class="title-set"><h1>SORT POST SETTINGS</h1></div>
            <table class="mytable">
                    <th>Posty Type</th>
                    <td><input type="text" placeholder="Post Type" name="map_option_1" value="<?php echo esc_attr( get_option('map_option_1') ); ?>" size="50" /></td>

                    <th>Meta Key</th>
                     <td><input type="text" placeholder="Meta Key" name="map_option_2" value="<?php echo esc_attr( get_option('map_option_2') ); ?>" size="50" /></td>
                     <td><input type="checkbox" placeholder="Meta Key" name="map_option_3" />Name<br>
                      <input type="checkbox" id="cb_name" name="map_option_4">Price<br><input type="text" name="metakey" id="metakey" placeholder="Meta Key"></td>


                    <td><?php submit_button(); ?></td>


I hope you can help me, this is my first time creating a wp plugin. Thank you!

1 Answer 1


Your code just outputs empty checkboxes. You have to check each box's value and then set checked="checked" if it's true.

<td><input type="checkbox" placeholder="Meta Key" name="map_option_3"
    <?php // check whether map_option_3 was saved
    if(isset(get_option('map_option_3'))) { ?>checked="checked"<?php } ?>
<input type="checkbox" id="cb_name" name="map_option_4"
    <?php // check whether map_option_4 was saved
    if(isset(get_option('map_option_4'))) { ?>checked="checked"<?php } ?>
/>Price<br><input type="text" name="metakey" id="metakey" placeholder="Meta Key"></td>

You should also make name and price into actual form labels, not just plain text beside the boxes. :)

  • Thanks, but this makes the page "This page is not working, HTTP ERROR 500", But it finally works when I removed the 'isset'. Thank you! Jun 23, 2018 at 8:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.