You’re setting a value whether it’s checked or not with this line:
$chk = ( isset( $_POST['special_box_check'] ) && $_POST['special_box_check'] ) ? 'on' : 'off';
The value is going to be either on
or off
, so your if
condition is always true, since it always has a value.
You could change it to save only if it’s checked, or delete it if it’s not. That way your condition will work, and you won’t have extra meta entries just to save the off state.
if ( isset( $_POST['special_box_check'] ) && $_POST['special_box_check'] ) {
add_post_meta( $post_id, 'special_box_check', 'on', true );
} else {
delete_post_meta( $post_id, 'special_box_check' );
}
Related Posts:
- How to update custom fields using the wp_insert_post() function?
- Most efficient way to add javascript file to specific post and/or pages?
- Display all values of custom a field created with ACF on a page
- Adding custom input for data attribute in insert media modal
- How to automatically apply woocommerce product title to all product images alt tags?
- How to handle a custom form in wordpress to submit to another page?
- If Custom Field is empty don’t display div
- How to display multiple Post meta_key/meta_values by SQL query
- Custom Meta Field – Youtube embed
- WooCommerce: How to display item meta data in email confirmation using woocommerce_order_item_meta_end
- How to make an meta_query optional?
- How to use multiple query with same meta key
- How can i create a function to get youtube video time
- Getting movie and serial on actor page
- How to loop over custom fields in a page template?
- Add custom field to attachments in a specific category
- Match checkbox data with page title to show certain items
- Print html when custom field has value inside while loop
- Update WordPress Custom Field with AJAX on cached page
- Geocoding an Exploded Custom Field Array
- How can update custom meta for all posts
- Unique key for each row in a repeater field
- Trying to retrieve meta values from three different meta keys and display in rows
- WP post meta – for loop inside for loop
- custom fields anchor points php
- Store custom field’s multiple values in one user meta key
- Get field in readable word
- WooCommerce multiple custom fields code
- When working with a post, almost all wp_postmeta are deleted
- What syntax is this? “{{post.price}}”
- Updating Lat and Lng of posts automatically gives sporadic results
- How to display custom field from a gallery thumbnail?
- WP_query meta_query slow with OR and DATES
- Get meta_query value by user meta array
- How to use something like meta_query but for fields?
- Getting a value from a custom field from a page that shares a parent with the current page
- meta field for numerous links
- Custom fields changes the formatting of metabox input
- Include a custom field in mysql query
- Display Content Based on Custom Field Value
- php if, else & custom fields – syntax error
- How to get the first letter from custom field?
- Meta box not saving spaces
- divide custom field values in div every two values
- custom field meta-box with dropdown/autocomplete
- Showing custom field contents without listing description
- How to exclude post from being queried based on custom meta value
- If custom field doesn’t exist, or exists and it’s true show title?
- How to link a word comprised of a custom field with another?
- Custom field in title
- If Elseif Query
- How can I put a custom field as the link of a button shortcode?
- Outputting a custom field in PHP
- Sorting Meta Fields?
- Custom fields randomly stop working
- Display selected parts from selected pages on the frontpage?
- Where can I find the code for the menu page meta boxes?
- How to echo a different field if another field is empty?
- How to use custom fields to replace top-level parent title with an image using wp_list_pages?
- PHP Puzzle: Unique Styles with PHP loop
- I want Page titles and excerpts to show up on home.php in certain order
- Posts sortable column not sorting properly for custom field numbers
- Search result page – display values from the result’s metaboxes
- Display custom meta box in my template file
- Query posts by custom fields (object post)
- ACF Date fileds to Age Convert [closed]
- Save custom field value to variable for conditional – why is this not working? [closed]
- Metadata on the WP_Post object
- Appending an ACF custom field to the page title
- Too many if’s and else if’s ?? – Must be better way [closed]
- Advanced Custom Fields Show PHP in Text Areas
- WP query with variables gives no result for specific user
- Grabbing value of input field inside of array
- Displaying custom meta box value in a custom post page
- How to initialise WP_Query on the basis of a specific meta_value and continue iterating rest?
- Convert custom field date format to “WordPress default”
- I want to show image from custom field image on my custom page template
- How can I change the location where the custom field is displayed in the Quick Edit tab in WordPress
- How do I organize posts based on their taxonomy?
- How do you create a front end form that enables the editing of member-specific custom fields in WordPress?
- Search custom post type posts only by meta fields?
- How to pass value to add_filter wpcf7_form_tag from another function?
- Custom Admin Menu Report for Specific User ID
- Shortcode Displays 2 times
- How to execute a shortcode within a custom field?
- ACF number less than comparison not working
- fetch from an external api call and display results in page
- Problem with custom user fields default value and retrieval
- Cannot Access ACF Field Values via my Plugin
- wordpress-plugin (widget) that performs a Neaby-search on the openstreetmap-endpoint: around x find y
- How to create advanced custom fields for backend content
- ACF block gutenberg aligncenter don’t work
- How to pull through page title depending on which radio button is selected on the specific page?
- Display WooCommerce Order Custom Field In Template (HPOS)
- How can I display a layout differently depending on whether the user is on Mobile or PC?
- hide “Open in New Tab” checkbox in link field
- Want to add custom post type for facebook feed
- Exclude function for custom pages, exclude custom ACF fields
- Custom rest fields not loaded in rest api cpt response
- Display posts in correct month order using single date custom field