Skip to content
Read For Learn
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP

displaying an error before update_post_meta

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:

  • Incorrect data after modifying post using backlink from wp_die
  • Require tags for bbPress topics

Related Posts:

  1. Getting post meta data, while editing a post in wp-admin panel [closed]
  2. special characters after saving draft interpreted as �
  3. Get Post ID in Admin Edit screen otherwise generate it?
  4. add_post_meta displays in admin edit area
  5. Wp doesn’t save meta box data
  6. Organizing Code in your WordPress Theme's functions.php File?
  7. How to check if a user is in a specific role?
  8. Can I rename the wp-admin folder?
  9. How do I Enqueue styles/scripts on Certain /wp-admin Pages?
  10. Changing Admin Menu Labels
  11. Adding custom columns to custom post types
  12. Adding Fields to the Category, Tag and Custom Taxonomy Edit Screen in the WordPress Admin?
  13. adding custom stylesheet to wp-admin
  14. Can’t change language (only “English (United States)”)
  15. Is there ANY way to remove comments function and section totally?
  16. How to use “menu_order” field for posts?
  17. Passing error/warning messages from a meta box to “admin_notices”
  18. “Too many redirects” ONLY when trying to access wp-admin page
  19. How to restrict dashboard access to Admins only?
  20. Admin Page Redirect
  21. Disable dragging of meta boxes?
  22. Toggle admin metabox based upon chosen page template
  23. Unable to login and wp-login.php redirects to wp-admin%2F&reauth=1?
  24. When moving a WP site, why does wp-admin redirect to old site?
  25. How to disable the “Post Lock/Edit Lock”?
  26. adding the category to the admin column for a custom post type?
  27. How can we make managing lots of pages in WordPress Admin better?
  28. Change page title in admin area
  29. do_shortcode() within Admin Page
  30. How can I control the position in the admin menu of items added by plugins?
  31. Changing the ‘wp-admin’ URL to whatever I want
  32. Unit testing in the WordPress backend (is_admin() is true)
  33. Admin ajax request return 0 with die()
  34. How to prevent access to wp-admin for certain user roles?
  35. How to remove screen options and help links in the admin area?
  36. How to remove the core embed blocks in WordPress 5.6?
  37. How to increase the file size limit for media uploads?
  38. Create WP tutorial for users with admin pointer using next button for navigation
  39. I’m getting a 404 message when I try to access wpadmin
  40. Taxonomy dropdown metabox in the back-end
  41. wordpress wp-admin css not loading
  42. Sort admin menu items
  43. How to order by post meta name in wp admin?
  44. How set defaults on wpLink()
  45. Remove dashboard, use Pages tab as default
  46. How to redirect/rewrite all /wp-login requests
  47. Show all post tags on post edit screen/sidebox
  48. How to hook in and modify the new revisions UI (3.6+)?
  49. How to display a static HTML page while setting up a WordPress site?
  50. Limit widget to certain sidebar?
  51. How can I uninstall a language?
  52. Check if user is admin by user ID
  53. My wordpress site gets redirected automatically to the old site any known solution for this?
  54. Best way to present options for home page in admin?
  55. Use a different domain for SSL
  56. Remove specific items from Quick Edit menu of a Custom Post Type?
  57. How to filter by post-format in admin?
  58. Unable to login to my wordpress site. reauth=1 redirection loop
  59. Add “external” link to admin menu in the backend
  60. How to Layer 7 Load Balance WordPress Backend and Frontend?
  61. Disable image attachment links
  62. How can I improve the line break handling in the WYSIWYG editor?
  63. Execute action after post is saved with all related post_meta records (data)
  64. wp_list_tables bulk actions
  65. Custom column for changing post status via ajax
  66. How do I change the login logo URL and hover title?
  67. update_post_meta and update_field ony working when saving the post
  68. Custom login redirects to wp-admin on wrong password
  69. How to remove comments option from wp-admin bar and modify profile icon
  70. Remove “Time to upgrade” message from dashboard
  71. Add header and footer to WP backend
  72. js error on post editing page
  73. How to search post by ID in wp-admin
  74. Remove ‘Custom..’ option in tinyMCE colour swatch
  75. sortable custom column in media library
  76. How to add a custom metabox to the Menu Management admin screen?
  77. how do I force a single column layout in screen layout
  78. How can I enable Google Analytics on a file download link?
  79. What is the best method to close off the backend?
  80. How to add custom submenu links in wp-admin menus?
  81. How to list ALL Pages in the dashboard?
  82. .htaccess in wp-admin produces a redirect loop
  83. Change Login URL Without Plugin
  84. Highlight custom widgets in the admin area?
  85. Checklist of selected categories
  86. Make fonts.com font work in TinyMCE (iframe referrer issue)
  87. How to Remove All Admin Bar Menu Items?
  88. Uploading Images in the Link Manager
  89. How can I make a Live Demo of my Premium Plugin? Are there security risks?
  90. Share same domain for wp-admin but for different website
  91. How to allow users login to WP from external domain and make REST requests
  92. How to change the wording in wp-admin back-end?
  93. Disable wp-admin console for subscribers
  94. Pre-fill fields with content from outside when creating a new post
  95. How do I find all admin users using phpmyadmin?
  96. Is there un-wp_autop function?
  97. Why are admin scripts not printed
  98. Edit specific nodes in WP_Admin_Bar
  99. White screen of death only in wp-admin
  100. Sortable admin columns, when data isn’t coming from post_meta
Categories wp-admin Tags post-meta, save-post, wp-admin
pagination for a custom loop with multiple post types
IF Custom field value equals ZERO

Recommended Hostings

Cloudways: Realize Your Website's Potential With Flexible & Affordable Hosting. 24/7/365 Support, Managed Security, Automated Backups, and 24/7 Real-time Monitoring.

FastComet: Fast SSD Hosting, Free Migration, Hack-Free Security, 24/7 Super Fast Support, 45 Day Money Back Guarantee.

Recent Added Topics

  • Bug in translation system: load_theme_textdomain() returns true, files are available and accessible but the language defaults to english
  • Custom Elementor controls not appearing in the widget Advanced tab using injection hooks
  • Get the name of the template/*html file used
  • Trying to Add Paging to Single Post Page
  • Sharing media files between live and staging servers
  • How to display the description of a custom post type in the dashboard?
  • Critical error on image display
  • Copying WP data and files into new install?
  • How to determine the DirectAdmin WordPress backup date?
  • How to get list of ALL tables in the database?
© 2026 Read For Learn
  • Database
    • Oracle
    • SQL
  • algorithm
  • asp.net
  • assembly
  • binary
  • c#
  • Git
  • hex
  • HTML
  • iOS
  • language angnostic
  • math
  • matlab
  • Tips & Trick
  • Tools
  • windows
  • C
  • C++
  • Java
  • javascript
  • Python
  • R
  • Java Script
  • jQuery
  • PHP
  • WordPress