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!
- Query Custom Post Types & category_name?
- How to add a “custom” date field to a custom post type?
- Custom post type with file upload – need to “set as field” instead of “send to editor”
- WP_Query search posts by custom post type and custom taxonomy
- Adding Meta Boxes while Registering a Post Type in a Class
- Dynamic Custom Post Type Plugin
- Order WordPress Custom Taxonomy Pages & Pagination Not Working
- I am having a problem with form updating/editing WordPress post on the frontend
- How to filter out post type meta?
- How to make in WordPress admin panel sortable column for the custom field, that count the number of page impressions?
- adding checkbox to meta
- How can I display my custom metaboxes on a custom post template?
- Display custom field of specific post where post title matches variable
- Conditional to modify query results
- Meta Box Only in CPT Edit Page, Not in Add New
- Loop through posts of a custom-post-type (event) and create .ics (iCal) file?
- different template for first and second level custom post page
- Output custom post shortcode. Help spot the error.
- How to count custom post types with conditional operators
- get_post_meta is returning image id
- Metabox Populated with a Custom Post Type – How to Output CPT based on Select?
- Is it possible to create a post using a metabox?
- WP_Query is printing out only one post when posts_per_page is set to multiple
- WP Query to displaying date and posts for that date?
- GravityForm: Populate Dropdown with custom post type [closed]
- Return array of categories to php function for current post
- Link users to a custom post type
- Create a random unique 6 digit number as custom field for custom post type
- How to output wordpress custom tags separated by comma?
- Loading all files within a directory
- Custom Post Type with metaboxes (no content) only?
- Blog page showing same content as homepage
- Custom Post Type Taxonomies -Posts not showing in Category or Tag pages
- Why do I lose the content of meta boxes when I leave the page?
- Dynamically add / duplicate custom meta in custom post types
- Add TinyMCE to CPT metaboxes in 3.1?
- Custom Post Type Metabox – Not Saving
- How can I show/add/save custom metaboxes as an Array of values?
- Using several custom fields as custom post title
- Custom Post Type without an archive page
- Get rewrite slug of custom post type in template
- Show Different Header on a Specific Post ID
- WordPress nl2br is not converting newline to html line break when saving metabox value
- Unable to show meta box data in frontend
- Get Post Primary Category
- Weird problem happening with custom taxonmy when creating/updating posts
- WordPress custom meta field for custom post not storing data
- Filter categories of posts with checkboxes
- Admin notice not displaying
- How can I create a custom meta box to add an mp4 video to a page?
- Can’t get order_by meta_value_num to work properly
- How to Duplicate (multiple meta box)?
- Create custom post type on successful woocommerce order [closed]
- advanced search forms with 3 input text and that the main problem 3 input text
- List custom post types in metabox
- Adding custom tables to WordPress
- Taxonomy Archive: Display only one post per term from separate custom taxonomy
- Create custom PAGE with register_post_type
- List of Posts in a Custom Field
- Save an array from drop-down in custom meta box
- Using My-Meta-Box-Class plugin, how is ‘Date’ value stored?
- Very Slow Page – How to Optimize # of Queries?
- Open div inside a custom post-type with Fancybox
- Pull a post based on a meta value in a custom post type
- Dynamic page outside WordPress
- Populate Custom Fields in a Custom Post Type?
- Change meta box when the page’s template is changed
- Duplicate Custom Header Functionality into the post edit screen
- Using wordpress template tags within an array
- Send email button in custom post type backend
- How to display Custom Post Type Post based on Tag with Shortcode Parameter?
- Custom query to filter posts that have current post as a taxonomy [closed]
- Custom post type permalink returns bad url
- Return the thumbnail meta data for getter and setter