Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function op_register_menu_meta_box() {
- add_meta_box(
- 'op-menu-meta-box-id',
- esc_html__( 'Custom offers Checklist (select any 2)', 'text-domain' ),
- 'op_render_menu_meta_box',
- 'listing'
- );
- }
- add_action( 'add_meta_boxes_listing', 'op_register_menu_meta_box' );
- function op_render_menu_meta_box() {
- // Metabox content
- $getPostsToSelect = get_posts('post_type=offers&numberposts=-1');
- foreach ($getPostsToSelect as $aPostsToSelect) {
- ?>
- <label>
- <input
- type='checkbox'
- name='yourcustom_meta[]'
- class='postsToSelect'
- value='<?php echo $aPostsToSelect->ID ?>'
- />
- <?php echo $aPostsToSelect->post_title;
- ?>
- </label><br />
- <?php
- }}
- 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' );
Add Comment
Please, Sign In to add comment