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

update post meta for checkbox in the admin when inserted in the front-end

Welcome to WordPress SO.

You may already have solved the issue as suggested by @Stevish, but just in order to avoid promoting the idea of checkboxes somehow being bad or difficult, I’d like to point out, that they’re perfectly okay and logical. 🙂

What is the problem in your first snippet, is the additional closing square bracket ‘]’ in the value, which would cause a syntax error and thus PHP Fatal error.

Change this:

update_post_meta( $post_id, 'checkbox_1', 'yes'] );

to this:

update_post_meta( $post_id, 'checkbox_1', 'yes' );

Also, a handy way to deal with single value metadata is to specify the $key and the $single parameter like this:

$value = get_post_meta( $post_id, 'checkbox_1', true );

That way you get the single value, and not an array where your value is the [0]. That way you can skip many if( isset( $meta['whatever'][0] ) ) kind of checks. 🙂

Related Posts:

  1. Save metabox with multiple checkbox array
  2. Add a Save Button to Custom Meta Box [duplicate]
  3. WP nonce field checkbox prints checked=’checked’ outside input field
  4. Any way to update_post_meta with html content? It gets stripped and becomes empty
  5. Adjust query on single
  6. Why is $_POST empty when saving custom Meta Box?
  7. Post meta vs separate database tables
  8. Get List of Registered Meta Boxes and Removing Them
  9. How to add tab which is visible only in admin side of product in woocommerce? [closed]
  10. Dashboard like meta boxes in my plugin – how to save their position and open/closed state?
  11. How to Use WordPress Color Picker API in Custom Post Type Metabox
  12. How to create Image gallery Metabox in wordpress [closed]
  13. How to enable users to down-vote in this simple voting counter (that uses the post meta)?
  14. Conflicting save_post functions when passing the post id and saving custom meta boxes for different post types
  15. How to add meta boxes to the ‘Add new post’ screen?
  16. Rearranging Dashboard meta boxes with use of plugin/functions.php
  17. How can I free up the memory used by update_post_meta?
  18. How to add multiple featured image in meta box in post editor?
  19. Plugin admin page meta_box toggle and order state not saving
  20. Is there a way to list tags order by post_meta field
  21. Metabox Not Showing on Custom Post Type But On Pages and Post
  22. Using radio button meta data from a custom meta box
  23. Is there a faster way than wp_insert_post to add content to a blog
  24. Best choice of options/settings framework for plugin/theme development
  25. Plugin development: get_post_meta is not working [closed]
  26. Ordering posts by metadata
  27. Act on user meta updated, but only once
  28. Admin auto-refresh is interfering with Firebug — how to prevent it?
  29. Show add_meta_box by selecting a specific category
  30. How to check if Woocommerce Order number equals to post ID?
  31. Use wp_set_post_terms() instead of wp_insert_post()
  32. Set page template programaticlly in plugin
  33. 403 Error when text is pasted in Custom Metabox Textarea
  34. Custom Taxonomy to dropdown box on adminside wordpress
  35. Create & Save multiple Meta-boxes
  36. Saving value of a selection option in comment form as comment meta
  37. Dashboard – get status and position of metaboxes and pass them to ajax method
  38. Plugin with action ‘save_post’ needs to press publish twice on order to publish
  39. Getting List of all registered Dashboard Widgets
  40. what is the difference between these phares?
  41. How to get Metabox custom field to show checked if value is updated using post meta query?
  42. How do I update a field of a meta box?
  43. Input value from metabox is not found in $_POST after post save
  44. Doubts about the use of metadata and how this can affect performance on WordPress
  45. update_post_meta not working in a loop
  46. Run Shortcode of post’s custom field in functions.php / Plugin
  47. Get draggable widgets on Edit Post page
  48. Including comments meta box on a plugin page
  49. How to add a widget to the post editing view?
  50. Adding admin menus to wordpress
  51. Remove all removed pages from wordpress
  52. Automating the process of shortcode generation in a plugin – how is it done?
  53. Meta box on options page save form problem
  54. Moving/dragging a metabox removes TinyMCE’s content
  55. Store custom meta box data as serialized array
  56. How to get custom post_author?
  57. Multiple array for post_content on plugin activation
  58. Ajax: Populate with content from a post’s ID not working – duplicating current page html instead
  59. Adding custom meta boxes to specified custom post type
  60. Issues Updating Post Meta with AJAX (Seems simple but cannot figure it out)
  61. How to add custom post widgets as tags into wordpress
  62. Using delete_post_meta for deleting multiple selected options
  63. Get audio metadata on file upload
  64. Plugin can’t be activated [closed]
  65. Plugin to create Posts and Forums then choose category and parent forum
  66. Remove Meta-boxes (Yoast SEO plugin) [duplicate]
  67. Is there a way to add a link with add_post_meta?
  68. Can I attach a plugin via my add_filter callback contents?
  69. Metabox is not displaying
  70. Catch metabox values in Plugin
  71. want to show CMB2 metabox on woocommerce product data tab
  72. Creating posts with links from a txt file
  73. Using wp_mail to send email?
  74. How to show comments from different Plugins to same post type?
  75. How to check if `comment_meta` exists before inserting the comment?
  76. How to get the `comment_post_ID`?
  77. WP_List_Table Inside Metabox With Bulk Actions Not Working on Submit
  78. Posts form with AJAX request – Plugin development
  79. Custom plugin foreach wp_insert_post not working
  80. Condition to check previous next article post title
  81. register_meta not showing custom post type metabox data in rest api
  82. Insert, update or remove data from database (usermeta)
  83. Save meta box data from selected dropdown list in bbpress reply form
  84. Sanitize WordPress Array Input?
  85. Metabox types list
  86. How to prevent wp_insert_post from creating a new post every second?
  87. WordPress Filesystem create CSS-File – get Shortcode ID for Name
  88. How to save multiple values in custom post type from front end to back end
  89. add_meta_box does not display meta box in Admin
  90. Add WordPress Meta Box saved form input to WordPress RSS feed [duplicate]
  91. set a custom post type to a taxonomy term programmatically in metabox
  92. Unexpected issue when using attachment_fields_to_edit filter
  93. WordPress delete mysql rows with string
  94. Dynamically getting tags in post edit screen
  95. Saving post meta
  96. Displaying Custom Post Meta
  97. How to show metabox just in post.php in admin?
  98. Getting duplicate page when activating my plugin
  99. Plugin dev: How to multiply instances of a plugin in the same metabox?
  100. Include add_post_meta in a plugin
Categories plugin-development Tags metabox, plugin-development, post-meta, wp-insert-post
What is the function to get options of the parent site of a multisite network?
How has my WordPress editor become so basic? Cannot add blocks or see anything visual

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