Actually, your code is working, as long as $val == 'on'
.
Did you try debugging by doing echo $val
?
If it’s still not working, try hard refreshing (Ctrl + F5) your webpage, checkboxes tend to keep their state on normal refresh (F5).
Also, please put your code directly on this forum, so the code is always accessible for future viewers 😉
Related Posts:
- How to get custom field image url of specific size
- Assign / update custom field value for all posts (How can I assign only to posts without custom field value?)
- What snippet do I need to type to show my ACF field show up on my theme?
- Is there a way to make [Table Of Content] plugin while not using revision data?
- get_post_meta shortcode returns empty field
- How to get post that has non zero or greater than zero meta value
- Update Multiple Post Meta for the Same Post In One call?
- How can I show drafts in wp_dropdown_pages list?
- How can I save repeatable fields with one value inside an array?
- Add custom meta box on Post page
- how to display all posts Custom fields dynamically?
- How can I add a custom meta value on file upload?
- Advanced Custom Fields query
- Datepicker not supporting timepicker
- How do I add advanced custom fields / meta fields to Elasticsearch? [closed]
- How WordPress autosave can save plugin fields?
- How to create Repeater fields using Advanced Custom Fields?
- Plugin allowing for artists, events and venues
- How to change ID of an attachment in wp_posts and its related tables correctly?
- Add multiple attributes to product from php
- How to remove duplicate Custom Fields?
- WordPress CMB2 – Run function on save
- Where to hook my plugin’s action
- Is there a filter for get_post_custom()?
- dynamically generating plugin syntax
- Carbon Fields use in custom plugin class
- How I can get custom field’s current value?
- UnWanted Custom field added in the wp page edit area
- Woocommerce – How to populate custom select field with stored values on checkout page?
- How to query the custom fields by language?
- What is generating my meta og:description?
- Creating a custom post type, adding custom meta fields, preventing all future editability of posts of this type
- How to toggle between two custom fields in WordPress woocommerce ‘WC Product Field Group’ plugin?
- WordPress Post Visibility Options for Frontend
- Custom User meta field display
- Bulk update all posts from plugin settings screen
- Unable to select image using custom image field type
- Custom fields for custom post type
- Redirect to another page using contact form 7? [closed]
- Every new post/draft has a custom field variable “yst_is_cornerstone” showing
- How to insert multiple postmeta values with one query?
- Mass SQL WordPress Meta Key deletion
- Date format – Meta Box plugin
- get meta value from database by post id
- Adding class to last list item? Not WP generated
- How to Resize the Custom Post Images?
- Amazon.com intergration with WordPress?
- Sticky option for custom post types without using custom fields or plugins
- Adding custom meta boxes to specified custom post type
- Set Multiple Meta Values as an Array Using dispatch( ‘core/editor’ ).editPost() Call in Gutenberg/JS
- How can I concatenate variables to search results title? [closed]
- How to add an extra, independent set of custom fields?
- How can I store data from custom fields to custom tables?
- Remember the Meta Value With Radio Buttons
- Plugin that lets visitors Like a post (not facebook) and stores likes in custom meta?
- Parent Child Custom Fields with Advanced Custom Fields
- grab or load text on demand
- Advanced Custom Fields Plugin – Images not displaying
- Adding custom Field To The Posts Listing
- Why does “updated_post_meta” did not fire when uploading media other than image?
- Table of contents (TOC) plugin is not showing header tag
- Help with autofilling field
- Register PODS Custom Field with WPGraphQL [closed]
- Add an action based on custom post meta field
- how to auto random increment for post view
- Adding Custom Endpoint in WordPress Rest API
- General Term for this form Field
- How do I change the functionality of an image slider which is part of ACF?
- Make custom post types using ACF
- Custom Field used to allow a Free Story; no longer works
- Performance considerations – postmeta table versus new table for custom posts with foreign keys?
- How to pass multiple custom fields as shortcode’s parameters
- How to create meta fields with more than 1 relation?
- Custom plugin issue – Notice: Trying to get property of non-object in
- If I am not writing a theme, how do I add custom fields to a user for a plugin
- Taxonomy question
- How can I call functions from a custom plugin?
- Problem with conditional woocommerce custom checkout field
- Delete postmeta when uninstall/delete plugin
- Same Title on two different post type with single custom taxonomy
- Add custom field for users
- How can I make my plugin display custom post meta data on the front end?
- Need help getting a certain value out of a multi dimensional array
- Creating a user ‘add custom field’ section
- What method should I use for a sidebar widget that reads latest posts?
- Add meta tags with a plugin?
- WordPress User Frontend Editing Custom Fields
- get_post_meta does not work
- ACF: Hide a div or template section when a custom field (in a field group) is empty
- wordpress last all added get meta value by post id
- Get post id in Post Page within Wp-admin
- How ACF Advanced Custom Field works with Woocommerce Single Product [closed]
- How do I add custom fields to the “Edit page” admin screen?
- Displaying Random Image from ACF Options Page [closed]
- Need help saving input fields for Security Deposit plugin in WC Vendors page
- Adding a variable to a meta field in the backend?
- How to change data format in custom meta box field [closed]
- Render CMB2 select option to post page [closed]
- Update post meta Rest Api
- Is there a plugin or another way that can help me find out the underlying files of a page/post? [closed]