Guest User

Untitled

a guest
Mar 22nd, 2018
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. function op_register_menu_meta_box() {
  2. add_meta_box(
  3. 'op-menu-meta-box-id',
  4. esc_html__( 'Custom offers Checklist (select any 2)', 'text-domain' ),
  5. 'op_render_menu_meta_box',
  6. 'listing'
  7. );
  8. }
  9. add_action( 'add_meta_boxes_listing', 'op_register_menu_meta_box' );
  10. function op_render_menu_meta_box() {
  11. // Metabox content
  12. $getPostsToSelect = get_posts('post_type=offers&numberposts=-1');
  13. foreach ($getPostsToSelect as $aPostsToSelect) {
  14. ?>
  15. <label>
  16. <input
  17. type='checkbox'
  18. name='yourcustom_meta[]'
  19. class='postsToSelect'
  20. value='<?php echo $aPostsToSelect->ID ?>'
  21. />
  22. <?php echo $aPostsToSelect->post_title;
  23. ?>
  24. </label><br />
  25. <?php
  26. }}
  27.  
  28. function wpse_admin_print_scripts_edit() {
  29. echo "<script>var limit = 2;' .
  30. 'jQuery('input.single-checkbox').on('change', function(evt) {' .
  31. 'if(jQuery('input.single-checkbox:checked').length > limit) {' .
  32. 'this.checked = false;' .
  33. '}' .
  34. '});</script>";
  35. }
  36. add_action( 'admin_print_scripts-post.php', 'wpse_admin_print_scripts_edit' );
Add Comment
Please, Sign In to add comment