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' );
Related Posts:
- Using ‘strtotime’ function to convert a custom-meta-box to a date-stamp
- Timepicker-addon doesn’t show – Datepicker works fine?
- Using WPAlchemy metabox values in another metabox
- A good strategy to print custom posts (offer) that are checked inside the metabox of a post?
- window.send_to_editor and jQuery .attr() conflicts with multiple custom upload image meta boxes
- Getting the URL of the parent page
- What’s the difference between same wp functions get_posts(); functions in different form?
- Push metadata in array
- Troubles with saving metabox
- Why are taxonomy terms not saving when using custom meta boxes with radio button taxonomy selectors?
- How to Upload CSV Data into Custom Post Type Data with Metabox programmatically
- How can I move (or create another) publish button?
- Add additional field to custom post_type
- Meta-Boxes for CustomPostType cause PHP Errors and Notices in “Add New” view
- I can’t connect my custom jquery to wp admin
- Change Dropdown jQuery to show/hide but with default place holder that shows all
- I’m having trouble with Related Product “tax_query” ‘terms’ value
- Get meta values from parent post and save in child post
- Collect custom post in a calendar
- Meta box not saving
- Meta Box not being added in plugin
- Meta-Box to add multiple items one at a time and on publish save all
- Toggle a metabox based on a selection
- Add text to metabox input text field from Thickbox
- How do loop categories post from according in WordPress? is it impossible to solve this problem?
- Just the First Metabox what saves the data!
- Do I need a nonce field for every meta box I add to my custom post type admin?
- Help Creating a Slideshow Custom Post Type with Custom Meta Boxes?
- How to force one column layout on custom post type edit page?
- Custom Post Type – Taxonomy Dropdown Menu?
- How to add multiple images to custom post type?
- How do I programmatically add items of content to a custom post type?
- Creating a Custom Post Types dropdown in a Meta Box
- Ajax filter with custom taxonomies
- WordPress metabox file upload in custom post [duplicate]
- Display metabox conditionally
- Embed ‘New Post’ Form Inside ‘New Post’ Form
- How to stop wordpress from mangling HTML in a metabox textarea
- Adding a span when custom post type is updated
- Hiding Metabox from Screen Options Pull Down
- How to: add option to add more checkboxes on custom post type
- how to set default value for checkbox in wordpress
- How can I show/add/save custom metaboxes as an Array of values?
- Save an array from drop-down in custom meta box
- Custom post type permalink returns bad url
- Custom meta box not saving
- How to display selected taxonomies by their parent
- Custom Field Order by Last Name and First Name
- get the custom post type title/name
- WordPress 3.5 Media Uploader – Only allow 1 upload and certain file types
- Make metabox of custom post type fully autosave- and bulk-/quick-edit compatible
- Custom Post Type uses Custom Tags in add_filter?
- get_post_meta not working on publishing
- Getting Custom Post Type Meta on Publish
- WordPress custom post type split into pages
- Assign External Database Queries to Global Variables and Make Them Accessible
- Checking if $_FILE isset for an array of file upload metaboxes
- Different Category system needed for the Custom Post Type
- Specifying Mouseover Icon for Custom Post
- Sizing textarea field in custom metabox
- Why won’t this jQuery code work?
- Custom post-type metabox position
- How to add editable/dynamic values to dropdown of a Custom Post Type Meta Box
- How can I set a meta value that will then affect other post meta values?
- How to Use Custom Meta Field Instead of CPT Title in Post URL
- Query custom post types & Taxonomies and list them in a table on a page
- Nested Custom Taxonomies | Incorrect posts when querying
- Is it possible to sort metabox teaxtarea values?
- wp_editor for custom post type doesn’t save value
- How do I get the index for a custom post?
- Commas not displaying in implode
- add custom tags for custom post type in wordpress
- foreach loop inside the loop creating duplicates in output
- List of all posts in one custom post type in the edit screen of another
- Display custom-post type based on the Title matching the current selected value
- Custom Post Type Causes Error: Warning: call_user_func_array()
- Is it a connection or relationship between 2 custom post types?
- Custom front-end form for adding post – Category problem
- update custom taxonomy custom fields
- Filter taxonomy by CPT
- Sort custom post column by generated value?
- create a “add icon” field in taxonomies page
- Custom post type order by post_title
- Tell wordpress to show a single page instead of an archive page
- Getting data from dynamically allocated metaboxes within a custom post
- PHP Notice: Unidentified index
- check_admin_referer not working in custom meta box for custom post type
- Custom meta box in editor of custom post type not working
- get_post_meta for Custom Post Type ( CPT )
- How to display all custom fields associated with a post type – IN THE ADMIN AREA?
- How to make post page unique and show it on home page?
- Default taxonomy ‘post_tag’ added to CPT managing by custom role : nothing in the metabox
- Custom Search not working
- Add multiple custom meta boxes to different custom post types
- How to bring custom meta boxes to custom post types?
- WordPress Set A Static Page/Template For All Sub-Pages
- Add HTML before a specific div?
- How to hide home title on pages and posts?
- Is there any way of not using my_init_method in the following code (that creates a custom post type)?
- Display ONLY ONE $term (Out of 4 terms) from a Custom Taxonomy and CPT