How to save the checked boxes?

You can use PHP in your functions.php file to insert inline JavaScript (including jQuery) using WordPress hooks.

In your example, you could use the admin_print_scripts-post.php action hook to print your inline jQuery like so:

function wpse_admin_print_scripts_edit() {
  echo "<script>var limit = 2;' .
    'jQuery('input.single-checkbox').on('change', function(evt) {' .
      'if(jQuery('input.single-checkbox:checked').length > limit) {' .
        'this.checked = false;' .
      '}' .
    '});</script>";
}
add_action( 'admin_print_scripts-post.php', 'wpse_admin_print_scripts_edit' );

Leave a Comment

tech