I think you’ve way over-complicated things. Assuming private
is a checkbox, just check for it being set, and act accordingly. With form $_POST
data, a checkbox will send its value if checked, and will send nothing if not checked:
if ( isset( $_POST['private'] ) ) {
update_comment_meta( $comment_id, 'private', 'private' );
} else {
delete_comment_meta( $comment_id, 'private', 'private' );
}
Note that, since a checkbox is binary (checked/unchecked), you can hard-code the value into your update_comment_meta()
call, thereby inherently sanitizing the user input.
Related Posts:
- Adding another state (spam, reject, approve) to wordpress comments?
- comments_where Hook
- Echo out custom fields in comments
- Show only posts which can be commented OR have custom meta field
- Show Custom Comment Fields when editing in admin
- How to make custom comment fields required and message field not required
- Comments form custom fields order
- How to add a title field in comments?
- Add & store extra fields – WordPress Comments
- displaying and sorting comments by a custom field (using PODS plugin) [closed]
- Declaring in variables [closed]
- comment meta_query for keys that aren’t yet set
- custom comment_form fields not displaying
- Rewrite comment form post ID on submit
- add_comment_meta not working properly
- Semi-Private Comments + page comments -> is it possible?
- How to add a custom field to the comments “Quick Edit” screen?
- file upload user profile
- i want to send email on custom post field (job_status == 2) but it is not working
- Filter Query Post by Custom Fields(by date)
- Show only first image of multiple image field
- How to add google map to custom field
- update_post_meta based on acf repeater field
- Can’t sort custom column on user.php by number / meta_value_num?
- Foreach giving one too many list items, how can I remove the last empty line?
- Need to call this php function inside a modal window from text widget
- Custom field not showing
- Change Fields of Comments and make them searchable?
- Display filesize of custom field value
- I used a custom field for header image and can’t get it to show up on posts
- How to include custom field in shortcode (do_shortcode) in theme file
- How I can change PayPal IPN ‘custom’ field in woocommerce?
- jaredatch metaboxes on video post formats
- Query posts by Custom Meta (checkbox) & Genesis Grid Loop
- How to automatically create a custom field when a post is published?
- custom field with links
- Shortcode not picking up custom field
- add multiple values (array) to post meta_input
- Order by a meta field in query loop
- Assign class to Drop Down Selections in WooCommerce Products Custom Fields
- Grouped Custom Meta Fields without plugin
- How to display search query as formatted text?
- Problem display
- Google not index my Custom 404 page ?why?
- Dynamic background image used in css after selector
- Show/Hide Featured Image or replace it with custom field [closed]
- How to create a searchable database with a single-field search box at the front end? [closed]
- Tons of Custom Fields [closed]
- How can i put a custom field inside this php
- Add custom fields to specific menus
- Custom Fields after update to WordPress 6
- Custom fields: Split data from single custom field’s sub-array to separate custom fields when saving post
- How can I copy value from dropdown once I select it to text area as text?
- Dynamically update Custom Fields to display new dates
- Site uses wpdb to fetch meta_keys but just displays first meta_key from a page (the post uses the same meta_key “filmmaker” more than once)
- How to get all specific fields from one ACF Group?
- How to apply Local Business Google Schema dynamically on a Custom Post single template?
- Create taxonomy terms from custom field values
- Use country flag as user avatar based on comments IP address?
- Add fields to edit in custom widget
- Save Custom Meta Value on Media Upload
- Archive for custom fields?
- Truncating characters in Advanced Custom Fields works some places but not others?
- Set new url from custom post field
- How to make donation button dynamic on chariti theme [closed]
- Add CSS class to posts with certain meta key
- Is there a way to read JSON data inside Custom Fields without editing PHP? [closed]
- save all acf options in one meta_value [closed]
- Conditional display based on ACF checkbox
- How to add new Metadata options (Date, Author, etc.) for Posts?
- WP Query Args – search by meta_key or title
- acf field repeater link don’t work
- Can running a WP-Cron to update_post_meta cause performance issues?
- custom field value is blank or empty
- Saving multiple custom meta box fields
- How to add an ACF only for parent term?
- Match submitted array fields with the MYSQL database fields to update them correctly in PHP
- Best method for comment section associated with different images?
- Add functionality to block comment authors in the Comment edit pag
- Multiple triggers when publishing, saving or updating a post in WordPress
- If possible a field ID transfom in a Custom Field?
- Best way for managing images of ads banners
- Crop custom image size vs actual size
- ACF in radio button cf7
- Modal pop-up HTML code works on other sites or HTML viewers but not in the custom HTML block within a wordpress page?
- Set post status to draft after validating post meta values in save_post hook
- Automatically changing a posts status to draft based on magic fields [closed]
- Multiple permalinks for a single post from custom field
- Search for meta_query does not return any result if combined with title
- get Custom field label (select/dropdown) on front end
- get_the_ID() retrieves same ID on Gutenberg’s Query Loop
- How to display WordPress Twenty Twenty-Four’s built-in custom field in a post (or page)?
- How to conditionally display an ACF custom textarea contents only to those users chosen from an ACF User field
- Can I count every article following extracted meta value?
- Adding the numerical values from a custom field from all posts in a category
- Why the value of the selector doesnt remain visible in the custom field after I edit the post?
- How to hide a field on the frontend of a Buddypress page by field ID according to user roles and login status?
- Custom fields – get_post_meta giving null
- Custom fields empty after refreshing page
- I have design Tab in a Bootstrap 5 in row. And repeat row in ACF. only 1st row tab data is show. other row data off tabcontent appearing display:none