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

Where to put meta Keys

First of all you have an if statement that is always false in your save function.

I don’t see any input called wporg_field anywhere in your meta box, so most probably there is no such field – so that condition is false and no meta field is saved.

Another problem is that you make wrong assumptions on how checkboxes work. If checkbox is not checked, then it won’t be sent in POST array.

Here’s a fixed version – it should work:

function wporg_save_postdata($post_id)
{
    if ( array_key_exists('include_in_image_gallery', $_POST) ) {
        update_post_meta(
            $post_id,
            '_wporg_meta_key',
            $_POST['include_in_image_gallery']
        );
    } else {
        delete_post_meta($post_id, '_wporg_meta_key');
    }
}

Related Posts:

  1. Getting attachments by meta value
  2. Get attachment by meta_key value
  3. How to only display posts whose meta_value field is not empty?
  4. Can wp_query return posts meta in a single request?
  5. order by numeric value for meta value
  6. Broken? WP_Query and “attachment” as a post type
  7. How do I query for posts by partial meta key?
  8. Use REGEXP in WP_Query meta_query key
  9. WordPress retrieving meta data for all custom post types in list view
  10. Order by optional meta key?
  11. meta_query: using BETWEEN with floats and/or casting to DECIMAL
  12. Is it possible to query all posts that don’t have an attachment?
  13. How to paginate wordpress [gallery] shortcode?
  14. Reduce or prevent calling of update_meta_cache
  15. Is there a way to extend WP_query so Custom Post Types can have properties?
  16. What is the most efficient way of querying posts based on visits and date for current day?
  17. How to get Page/Post Gallery attachment images in order they are set in backend using WP_Query()?
  18. Count the number of images uploded on the website
  19. WP_Query displaying ALL posts
  20. How to paginate attachments in a secondary query as gallery?
  21. meta_query where value is equal to given value
  22. Query Custom Meta Value with Increment
  23. How do I exclude all images from a wp_query?
  24. WP-CLI How to generate a list of posts with corresponding meta values
  25. get images attached to post
  26. What is an efficient way to query based on post_meta?
  27. WP_Query not working as expected for attachments and custom meta_query
  28. How to count post meta key values for all posts in database
  29. Group posts by meta_key
  30. How should I use posts_where to change meta_value from a string to integer?
  31. How can I create a WP_Query that returns posts where one meta_value
  32. Get attached media only
  33. WordPress altering my custom query, How to fix it?
  34. WP Meta Query for some meta (array) values
  35. WP Query post meta value
  36. Would this post meta be better added to the post table rather than post_meta table
  37. Custom URl parameter
  38. query posts in functions.php and update a field
  39. Compile meta values from custom loop into array and then calculate sum total
  40. How to get sum of meta_values of a meta_key in wp_query according to conditions
  41. how to fire join query with post_meta
  42. Best approach to create Hot and Trending sections
  43. WP_Query, custom sort and custom filter
  44. query attachments of parent page if attachments of current page are smaller than …
  45. Order posts by meta value and Date
  46. Efficient way to update multiple post meta
  47. How to make orderby ‘meta_value_num’ OPTIONAL?
  48. wp_query for displaying attachments with a tag
  49. Query Posts depends on custom field inside repeater field using acf
  50. Show selected images on top in Media Manager
  51. Query post with meta_query where date is not in future
  52. Minimising Database Queries when using Advanced Custom Fields
  53. How can I query posts with newly uploaded images?
  54. Get meta info related to current post
  55. Select from wp_post and multiple meta_value from wp_postmeta
  56. Pull post meta with post_query?
  57. Sorting By Custom Posts With Attachments
  58. Attachment changing page’s permalink – $post not resetting?
  59. Group WP_Query by meta_key date
  60. WP_query posts closest to todays date
  61. How to fetch only media that was already attached to a post/page?
  62. exclude posts with a specific custom field and value
  63. Inserting serialized value into wp_postmeta using update_post_meta
  64. How to do meta_query for attachments?
  65. How to make Meta Query case sensitive?
  66. Performance when getting post meta for post retrieved by meta value
  67. Display custom field meta outside loop, site wide
  68. Using hook to use DISTINCT in a wp_query
  69. Fetch Record based on meta key dates
  70. How to show optimized list of posts with all their attachment images
  71. how to make members list directory through wordpress post custom meta key.
  72. How do I query for posts by partial meta key?
  73. Large AND OR query timing out
  74. get_post_meta slowing down my page load (in a plugin)
  75. New WP_Query loop in admin causes problems
  76. echo a specific meta_key queried through a custom post
  77. How to increase load time of an archive/search page (WP_Query)
  78. WP_Query Attachment adds additional attachment count and need to link attachment to post url
  79. get_post_meta in WP_Query
  80. Which is faster wpdb & get_row or wp_query & ge_post_meta?
  81. Hide posts with meta key in WP_Query
  82. Filter posts by comparing custom meta value against postdate
  83. WordPress query posts with multiple post_meta data
  84. WP_Query – Accessing MetaValue from Query Result
  85. search serialised meta_value for date value?
  86. How do I check if an article is popular this week?
  87. Why having more than 10 clauses in WP_Query results in some outputs being dropped?
  88. Woocommerce: order posts by meta key
  89. Order WP_Query results by meta key value in custom query
  90. How can I update post meta inside a WP_Query loop or the WordPress loop?
  91. Nested array issue in meta_query
  92. wp_query get attachments in larger size
  93. Display post meta conditionally based on it’s value
  94. Creating attachments archive in tags and categories
  95. Filtering by multiple conditions in the loop
  96. Sort by custom field that is an array?
  97. Orderby two meta fields not working
  98. Display count number of posts with the same specific meta_key meta_value
  99. Ignore image urls in wp_query search
  100. Query posts by searching for a string in a meta field
Categories wp-query Tags attachments, post-meta, wp-query
Is there a way to create a block template that is not limited to a post type?
How do I go about looping through a advanced custom field on a particular page inside of another page

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