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:
- Save metabox with multiple checkbox array
- Add a Save Button to Custom Meta Box [duplicate]
- WP nonce field checkbox prints checked=’checked’ outside input field
- Any way to update_post_meta with html content? It gets stripped and becomes empty
- Adjust query on single
- Why is $_POST empty when saving custom Meta Box?
- Post meta vs separate database tables
- How to add tab which is visible only in admin side of product in woocommerce? [closed]
- Dashboard like meta boxes in my plugin – how to save their position and open/closed state?
- How to Use WordPress Color Picker API in Custom Post Type Metabox
- How to create Image gallery Metabox in wordpress [closed]
- How to enable users to down-vote in this simple voting counter (that uses the post meta)?
- Conflicting save_post functions when passing the post id and saving custom meta boxes for different post types
- How to add meta boxes to the ‘Add new post’ screen?
- Rearranging Dashboard meta boxes with use of plugin/functions.php
- How can I free up the memory used by update_post_meta?
- Plugin admin page meta_box toggle and order state not saving
- Is there a way to list tags order by post_meta field
- Metabox Not Showing on Custom Post Type But On Pages and Post
- Using radio button meta data from a custom meta box
- Is there a faster way than wp_insert_post to add content to a blog
- Best choice of options/settings framework for plugin/theme development
- Ordering posts by metadata
- Act on user meta updated, but only once
- Admin auto-refresh is interfering with Firebug — how to prevent it?
- Show add_meta_box by selecting a specific category
- How to check if Woocommerce Order number equals to post ID?
- Use wp_set_post_terms() instead of wp_insert_post()
- Set page template programaticlly in plugin
- 403 Error when text is pasted in Custom Metabox Textarea
- Custom Taxonomy to dropdown box on adminside wordpress
- Create & Save multiple Meta-boxes
- Saving value of a selection option in comment form as comment meta
- Dashboard – get status and position of metaboxes and pass them to ajax method
- Plugin with action ‘save_post’ needs to press publish twice on order to publish
- Getting List of all registered Dashboard Widgets
- what is the difference between these phares?
- How to get Metabox custom field to show checked if value is updated using post meta query?
- How do I update a field of a meta box?
- Doubts about the use of metadata and how this can affect performance on WordPress
- update_post_meta not working in a loop
- Run Shortcode of post’s custom field in functions.php / Plugin
- Get draggable widgets on Edit Post page
- Including comments meta box on a plugin page
- How to add a widget to the post editing view?
- Adding admin menus to wordpress
- Remove all removed pages from wordpress
- Automating the process of shortcode generation in a plugin – how is it done?
- Meta box on options page save form problem
- Moving/dragging a metabox removes TinyMCE’s content
- Store custom meta box data as serialized array
- How to get custom post_author?
- Multiple array for post_content on plugin activation
- Adding custom meta boxes to specified custom post type
- Issues Updating Post Meta with AJAX (Seems simple but cannot figure it out)
- How to add custom post widgets as tags into wordpress
- Using delete_post_meta for deleting multiple selected options
- Get audio metadata on file upload
- Plugin can’t be activated [closed]
- Plugin to create Posts and Forums then choose category and parent forum
- Remove Meta-boxes (Yoast SEO plugin) [duplicate]
- Is there a way to add a link with add_post_meta?
- Can I attach a plugin via my add_filter callback contents?
- Catch metabox values in Plugin
- want to show CMB2 metabox on woocommerce product data tab
- Creating posts with links from a txt file
- Using wp_mail to send email?
- How to check if `comment_meta` exists before inserting the comment?
- How to get the `comment_post_ID`?
- WP_List_Table Inside Metabox With Bulk Actions Not Working on Submit
- Posts form with AJAX request – Plugin development
- Custom plugin foreach wp_insert_post not working
- Condition to check previous next article post title
- register_meta not showing custom post type metabox data in rest api
- Save meta box data from selected dropdown list in bbpress reply form
- Sanitize WordPress Array Input?
- Metabox types list
- How to prevent wp_insert_post from creating a new post every second?
- WordPress Filesystem create CSS-File – get Shortcode ID for Name
- How to save multiple values in custom post type from front end to back end
- add_meta_box does not display meta box in Admin
- Add WordPress Meta Box saved form input to WordPress RSS feed [duplicate]
- set a custom post type to a taxonomy term programmatically in metabox
- Unexpected issue when using attachment_fields_to_edit filter
- WordPress delete mysql rows with string
- Dynamically getting tags in post edit screen
- Displaying Custom Post Meta
- How to show metabox just in post.php in admin?
- Getting duplicate page when activating my plugin
- Plugin dev: How to multiply instances of a plugin in the same metabox?
- Include add_post_meta in a plugin
- save_post not called in plugin / custom field still saving overwriting metaboxes
- Get fields of a widget
- Display Data’s metabox in page
- Show Metabox Images in slideshow instead of static
- Add Page With Parent ID
- Yet another wp_insert_post infinite loop. What is wrong?
- How to set/change another post author by custom fields or something else?
- A better way of getting draft posts that has a particular post meta using get_posts function
- Saving metabox updates causing fatal error