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

How to validate select field in post meta?

Separate the allowed values in a function:

function get_allowed_values()
{
    return array('one', 'two', 'three');
}

In your metabox:

foreach ( get_allowed_values() as $item) {}

In your validation handler:

if ( isset( $_POST['select_meta'] ) 
    and in_array( $_POST['select_meta'], get_allowed_values() )
)

Related Posts:

  1. What is the index [0] for on post meta fields?
  2. Custom field metabox not showing in back-end
  3. How to hide meta box values from custom fields list?
  4. How to store the value of a custom field dropdown select for post referencing?
  5. Get updated meta data after save_post hook
  6. Create meta boxes that don’t show in custom fields
  7. Custom fields to save multiple values
  8. wp_handle_upload error “Specified file failed upload test” but still creates attachment?
  9. Create Multiple File Upload Metabox in WordPress
  10. Get updated meta value after post update or published (custom post type) using hook
  11. Button inside Custom Meta Box triggering the Update Button
  12. Why is my Custom Meta Box Field Inputs NOT saving?
  13. custom-meta-box checkboxes from loop won’t save
  14. get_posts in meta box dropdown not showing latest posts
  15. How can you include custom post meta in search without calling each key?
  16. Display Custom Meta Box Field Only If Value is Present
  17. shortcode in a custom metabox
  18. Problem with saving large amount of data in postmeta/usermeta
  19. Allow only one post with specific meta value
  20. Custom metabox not displaying multiselect data in edit mode
  21. Move Title and the Content WYSIWYG editor position
  22. How to use media upload on metabox post page without breaking TinyMCE?
  23. Let’s Create Custom Field Template Documentation
  24. How add multiple wp_editor_box to new post
  25. Can I save post meta programatically without setting metaboxes?
  26. Meta box values are displayed on Custom Fields list. Is it possible to hide them?
  27. If metabox has content display content
  28. put saved metabox values back into fields and then display on the front end
  29. How to improve my non-unique metadata MySQL entries?
  30. Set class if a meta value is set within post archive
  31. WordPress Blocks, setAttributes not saving
  32. Allow HTML in Custom Metabox area
  33. Custom field metabox not showing in back-end
  34. Save, update, get and sanitize post meta as HTML not plain
  35. Create Meta boxes dynamically
  36. Get meta value when the page is a blog archive
  37. Can’t save meta field value if the title not set
  38. Display Data From This Custom Media Upload Meta Box?
  39. When post is updated, custom metadata in text area field is overwritten
  40. wp_postmeta are updated for only one page
  41. added a meta box to post however when saving menu while debug on throws a warning
  42. When editing a post with a custom meta box the values aren’t displaying correctly
  43. How to add new Metadata options (Date, Author, etc.) for Posts?
  44. Saving multiple custom meta box fields
  45. Custom fields empty after refreshing page
  46. Can I exclude a post by meta key using pre_get_posts function?
  47. Add validation and error handling when saving custom fields?
  48. Passing error/warning messages from a meta box to “admin_notices”
  49. Custom post meta field effect on the performance on the post
  50. How to get custom post meta using REST API
  51. Custom field/meta populated by dropdown of existing posts?
  52. Difference between meta keys with _ and without _ [duplicate]
  53. Orderby meta_value only returns posts that have existing meta_key
  54. What is “meta_input” parameter in wp_insert_post() used for?
  55. How to enable revisions for post meta data?
  56. The “_encloseme” Meta-Key Conundrum
  57. Individual Widgets per Page
  58. Best way to programmatically remove a category/term from a post
  59. Gutenberg add a custom metabox to default blocks
  60. ‘Preview Changes’ for custom meta boxes?
  61. Using TinyMce with textareas in meta boxes on custom post types
  62. Using get_post_meta with new_to_publish
  63. add meta box – custom field : which to choose?
  64. Add metabox to document tab in gutenberg
  65. How to add add_meta_box to specific Page Template?
  66. So much data in postmeta
  67. Can I count the number of users matching a value in a multiple value key?
  68. When using add_post_meta and update_post_meta, is there any way to give the individual arrays keys?
  69. Auto sort the wp-admin post list by a meta key
  70. Adding another state (spam, reject, approve) to wordpress comments?
  71. get_post_meta() unserialize issue – returns boolean(false)
  72. What is the advantage of the wp_options design pattern?
  73. Arrange custom fields with drag and drop?
  74. Storing meta fields multiple times OR once with multi dimensional array?
  75. How can I avoid re-inventing the Custom Fields wheel in my Plugin’s Metabox?
  76. Unable to get Preview of Uploaded image within a Custom Meta box
  77. Allow user to create instances of custom field
  78. Using media-upload.php to upload mp3 via custom fields
  79. extend Meta Box / Document Panel
  80. display specific custom fields
  81. Save metabox with multiple checkbox array
  82. Is there a hook / action that is triggered when adding or removing a post thumbnail?
  83. Add custom option to Standard Page Attributes Meta Box
  84. Add multiple images to a page sidebar
  85. Meta keywords and descriptions plugin for manually editing meta for each page/post
  86. passing argument to get_template_part() or a better way to code
  87. Only show metabox when date-value in other metabox is over?
  88. Is it possible to store arrays in a custom field?
  89. Detect meta value changes when post is updated (post_updated)
  90. Multiple meta values for same meta_key adding on “Preview Changes” hit but not on saving or updating post
  91. Save HTML formatted data to post meta using add_post_meta()
  92. Custom Meta Boxes: Store two values in one repeatable field
  93. importing data from non-wordpress mysql db
  94. Check before publishing, if already exist post with current custom field value
  95. Better post meta efficiency?
  96. Populating meta box with select-list of existing posts, and assigning it to custom post types
  97. Transients vs CRON +Custom Fields: Caching Data Per Post
  98. How To Create a Metabox of HTML Content with Instructions For Editors When Editing a Post or Page?
  99. Unable to save datetime custom meta field using update_post_meta() function
  100. Up/Down voting system for WordPress
Categories custom-field Tags custom-field, metabox, post-meta, save-post
Only Display a Featured Image on First Post Page
wpdb prepare insert table doesn’t work

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