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

Make the checkbox meta field checked by default

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:

  1. How to get custom field image url of specific size
  2. Assign / update custom field value for all posts (How can I assign only to posts without custom field value?)
  3. What snippet do I need to type to show my ACF field show up on my theme?
  4. Is there a way to make [Table Of Content] plugin while not using revision data?
  5. get_post_meta shortcode returns empty field
  6. How to get post that has non zero or greater than zero meta value
  7. How do I hide posts across all loops based on the value of a custom field?
  8. How can I change the meta_key for a particular piece of information?
  9. WordPress Post Visibility Options for Frontend
  10. Custom User meta field display
  11. Bulk update all posts from plugin settings screen
  12. Execute js files doesn’t seem to work
  13. WordPress metaboxes – textfield suggestion automatically populated
  14. Char limit on custom blog-post form? [closed]
  15. Unable to select image using custom image field type
  16. Custom fields for custom post type
  17. Redirect to another page using contact form 7? [closed]
  18. Every new post/draft has a custom field variable “yst_is_cornerstone” showing
  19. Custom Post Type Fields
  20. Meta box losing its value when scheduled post is published
  21. How to insert multiple postmeta values with one query?
  22. How do I enforce users to fill a determined custom field using WyPiekacz?
  23. Mass SQL WordPress Meta Key deletion
  24. Date format – Meta Box plugin
  25. get meta value from database by post id
  26. Adding class to last list item? Not WP generated
  27. How to Resize the Custom Post Images?
  28. Amazon.com intergration with WordPress?
  29. Sticky option for custom post types without using custom fields or plugins
  30. How to remove bulk actions from custom post type
  31. Adding custom meta boxes to specified custom post type
  32. How to select a paragraph other than the 1st to be the post’s excerpt?
  33. How do we update a custom file upload field with the Advanced Custom Field plugin?
  34. Set Multiple Meta Values as an Array Using dispatch( ‘core/editor’ ).editPost() Call in Gutenberg/JS
  35. Order posts by meta key ( Using ACF )
  36. How to add fields in the WordPress editor?
  37. How can I concatenate variables to search results title? [closed]
  38. WordPress function to add text warning on every pages [closed]
  39. How to add an extra, independent set of custom fields?
  40. Price comparison table based on Custom Post Type?
  41. Show related posts based of current ACF field name in a single page post (a loop within loop)
  42. How can I store data from custom fields to custom tables?
  43. Remember the Meta Value With Radio Buttons
  44. Woocommerce – Change Variable Product Add to Cart to behave like external product using Custom Field (link) [closed]
  45. Custom Fields for Page Edits
  46. “After file loaded” action
  47. Plugin that lets visitors Like a post (not facebook) and stores likes in custom meta?
  48. Parent Child Custom Fields with Advanced Custom Fields
  49. grab or load text on demand
  50. How can I add user profile fields to my mailpress mailout
  51. Dictionary-style definition list plugin
  52. Advanced Custom Fields Plugin – Images not displaying
  53. Link Posts to External URL
  54. Adding custom Field To The Posts Listing
  55. How to create repeater field manually, without plugin (ACF Pro)?
  56. Creating New Dynamic Fields for a Certificate (Number Generation, Code Referencing, and more)
  57. Why does “updated_post_meta” did not fire when uploading media other than image?
  58. WordPress Phone Field Check (use numbers, spaces and pluses)
  59. Can export gallery but can’t import it Wp all import
  60. Table of contents (TOC) plugin is not showing header tag
  61. Auto populate a user custom field from another user custom field
  62. Best approach to make all tags searchable by the wordpress search function
  63. need to find duplicated meta value in custom filed and view the posts that have the same value
  64. Create a pdf from the entries in DB
  65. Help with autofilling field
  66. Help to Create a Simple Plugin to make a post
  67. how to find out which plugin disable custom field for post
  68. Preset custom fields
  69. What database state changes happen after a post is manually “updated” with no changes?
  70. Register PODS Custom Field with WPGraphQL [closed]
  71. Add an action based on custom post meta field
  72. how to auto random increment for post view
  73. custom fields not displaying on wordpress site
  74. WordPress hide post from custom post-type on a single page
  75. Create multiple posts when a custom post is created
  76. How to securely controlling data without keeping it in postmeta?
  77. Why Custom fields description is not working WordPress Version 5.4.2?
  78. Adding Custom Endpoint in WordPress Rest API
  79. General Term for this form Field
  80. How do I change the functionality of an image slider which is part of ACF?
  81. Make custom post types using ACF
  82. Problem Advanced Custom Fields PRO
  83. “Enable Media Replace” plugin does not update serialized object in WPMeta
  84. Custom Field used to allow a Free Story; no longer works
  85. Performance considerations – postmeta table versus new table for custom posts with foreign keys?
  86. Get and Update Most Meta Value as an array in HTML form
  87. How to pass multiple custom fields as shortcode’s parameters
  88. How to create meta fields with more than 1 relation?
  89. Meta Key array building with multiple input values from fields
  90. Get all user meta_keys and then group users by matching values
  91. Custom product page’s style for printing
  92. Custom plugin issue – Notice: Trying to get property of non-object in
  93. If I am not writing a theme, how do I add custom fields to a user for a plugin
  94. Taxonomy question
  95. Get value from an input field and pass into update_meta_data as $meta_value
  96. How can I call functions from a custom plugin?
  97. Creating Nested custom fields
  98. Problem with conditional woocommerce custom checkout field
  99. Create Biographies
  100. Delete postmeta when uninstall/delete plugin
Categories plugins Tags custom-field, plugins, post-meta
$wpdb insert is not work
“Class ‘Phar’ not found” error setting up WP-CLI with Cygwin

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