Short of doing some jQuery validation, I think the only option is wp_die()
.
add_action( 'save_post', array( $this, 'save_custom_items_data' ), 10, 2 );
public function save_custom_items_data( $post_id, $post )
{
if( count( $related_items ) > 5 )
{
wp_die(
'Error, 5 items max.',
'Error',
array(
'response' => 500,
'back_link' => true
)
);
}
else
update_post_meta( $post_id, '_custom-meta-items', $related_items );
}
Related Q&A’s:
Related Posts:
- Getting post meta data, while editing a post in wp-admin panel [closed]
- special characters after saving draft interpreted as �
- Get Post ID in Admin Edit screen otherwise generate it?
- add_post_meta displays in admin edit area
- Wp doesn’t save meta box data
- Organizing Code in your WordPress Theme's functions.php File?
- How to check if a user is in a specific role?
- Create WP tutorial for users with admin pointer using next button for navigation
- Taxonomy dropdown metabox in the back-end
- Add “external” link to admin menu in the backend
- Disable image attachment links
- update_post_meta and update_field ony working when saving the post
- Remove “Time to upgrade” message from dashboard
- Pre-fill fields with content from outside when creating a new post
- Why are admin scripts not printed
- White screen of death only in wp-admin
- wp-admin remove the subfolder URL
- Looking for a hook to add attachment information to the media library tab
- Removing admin bar from wordpress dashboard
- Load Balanced WP with single server admin access
- How to move wp-admin login page to another location? [closed]
- WP-admin giving 404
- How to control contextual help section by code?
- Can’t access wp-admin Internal Server Error 500
- WordPress admin not changing language
- Add custom text to Page Tamplate without need to know html
- Move WP Admin Bar
- Get Stylesheet To Showup in WP Admin Panel Editor
- Deprecated : contextual_help has been deprecated since version 3.3.0
- Just how ‘expensive’ is this function?
- Custom Background-Image not showing up
- Why is there an intermediate redirect to https://public-url.org/wp-admin?
- Remove query var on admin pages when ‘Save changes’ pressed
- How to hide wordpress default description box?
- admin_url in plugins
- Website looks fine, but login to wp-admin yields a blank screen
- Cannot find an OLD Gravity Form on an OLD Word Press site [closed]
- cannot find the login page for local WordPress site
- In editor-style.css how can I change background color of title field?
- Where did the screen options menu go?
- How do I change the upload file size limit in single-site wordpress install?
- Can’t call external stylesheet for WordPress admin (using wp_admin_css)?
- wrapping ‘rest_api_init’ in ‘is_admin()’ function
- display dynamic WP Site logo on wp-admin using CSS
- Restore a layout [closed]
- Logging into sandbox subdomain WP
- Page update through theme editor caused wp admin to break
- White screen of death on admin and other dashboard pages
- TinyMCE strips breaks inside editor
- can not access wp-admin after migrating to openshift
- Can I hook into wp_update_core outside of the admin?
- /wp-admin/ doesn’t work but /admin/ does
- Renaming wp-admin without hard-coding it. Is it really possible?
- WordPress Side Menu Admin Panel Default Order numbers List?
- Why can I log into wp-login.php and not wp-admin.php?
- update_post_meta not work [closed]
- firing function at login within class
- How to break line / add to ADMIN menu
- WordPress admin page not found error
- Outputting something based on the presence of post variable in admin screens
- Save meta data with post, Without using any plugin [closed]
- Use of domain name
- “Add New” button on custom post type grid
- Where is function to prevents non logged users access wp-admin?
- Registering for a domain on WordPress
- CSS of the admin panel
- Front end update_post_meta Help
- WordPress admin right sidebar isn’t working
- Why wp redirects me to wp-login.php when I visit a rewritten wp-admin URL?
- WordPress menu to change page title
- wp-admin blocking causing http error on uploads
- DISALLOW_FILE_EDIT is false but I still am not able to edit files from the admin interface and the menus do not show up
- Updated MAMP and localhost on MacOS site no longer accessible
- What hooks should you use to create a table only once?
- Custom admin menu order fails if slugs are complicated
- Cant access wp-admin
- Function to get a ‘post selector’ UI?
- Hi everyone, I have Problem with using wp_die()
- WordPress wp-admin Page
- How can I trigger a javascript function after a post update on edit post screen in wordpress admin panel?
- How do I create a customised table list of a custom post type (in the admin area)?
- restrict admin panel sections to users
- how to set not to be logined in wp-admin except administrator?
- CSRF attack to create USER
- Disable flyout (popup) menus in backend
- WordPress, content editor default type
- save_post doesn’t correctly process function call with php class
- Changing headers for an export from within a PHP class extension
- When installing wordpress through WP CLI mysite.com/admin not working
- Remove capability to interact with a page
- Random HTTPs redirections at admin area in shared hosting
- WordPress Login for multiple sites
- How do I change the WordPress Address URL only and still login to wp-admin
- wordpress wp-admin showing white screen with no error
- Undeletable posts, users or other content
- Blank sign in page
- Action for opening edit page in admin?
- Couple questions about .htaccess, login page, updates
- Is it possible to tell if a user is logged into WordPress from looking at the cookies which are set?
- if condition from post_meta not working in save_post