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:
- Getting attachments by meta value
- Get attachment by meta_key value
- How to only display posts whose meta_value field is not empty?
- Can wp_query return posts meta in a single request?
- order by numeric value for meta value
- Broken? WP_Query and “attachment” as a post type
- How do I query for posts by partial meta key?
- Use REGEXP in WP_Query meta_query key
- WordPress retrieving meta data for all custom post types in list view
- Order by optional meta key?
- meta_query: using BETWEEN with floats and/or casting to DECIMAL
- Is it possible to query all posts that don’t have an attachment?
- How to paginate wordpress [gallery] shortcode?
- Reduce or prevent calling of update_meta_cache
- Is there a way to extend WP_query so Custom Post Types can have properties?
- What is the most efficient way of querying posts based on visits and date for current day?
- How to get Page/Post Gallery attachment images in order they are set in backend using WP_Query()?
- Count the number of images uploded on the website
- WP_Query displaying ALL posts
- How to paginate attachments in a secondary query as gallery?
- meta_query where value is equal to given value
- Query Custom Meta Value with Increment
- How do I exclude all images from a wp_query?
- WP-CLI How to generate a list of posts with corresponding meta values
- get images attached to post
- What is an efficient way to query based on post_meta?
- WP_Query not working as expected for attachments and custom meta_query
- How to count post meta key values for all posts in database
- Group posts by meta_key
- How should I use posts_where to change meta_value from a string to integer?
- How can I create a WP_Query that returns posts where one meta_value
- Get attached media only
- WordPress altering my custom query, How to fix it?
- WP Meta Query for some meta (array) values
- WP Query post meta value
- Would this post meta be better added to the post table rather than post_meta table
- Custom URl parameter
- query posts in functions.php and update a field
- Compile meta values from custom loop into array and then calculate sum total
- How to get sum of meta_values of a meta_key in wp_query according to conditions
- how to fire join query with post_meta
- Best approach to create Hot and Trending sections
- WP_Query, custom sort and custom filter
- query attachments of parent page if attachments of current page are smaller than …
- Order posts by meta value and Date
- Efficient way to update multiple post meta
- How to make orderby ‘meta_value_num’ OPTIONAL?
- wp_query for displaying attachments with a tag
- Query Posts depends on custom field inside repeater field using acf
- Show selected images on top in Media Manager
- Query post with meta_query where date is not in future
- Minimising Database Queries when using Advanced Custom Fields
- How can I query posts with newly uploaded images?
- Get meta info related to current post
- Select from wp_post and multiple meta_value from wp_postmeta
- Pull post meta with post_query?
- Sorting By Custom Posts With Attachments
- Attachment changing page’s permalink – $post not resetting?
- Group WP_Query by meta_key date
- WP_query posts closest to todays date
- How to fetch only media that was already attached to a post/page?
- exclude posts with a specific custom field and value
- Inserting serialized value into wp_postmeta using update_post_meta
- How to do meta_query for attachments?
- How to make Meta Query case sensitive?
- Performance when getting post meta for post retrieved by meta value
- Display custom field meta outside loop, site wide
- Using hook to use DISTINCT in a wp_query
- Fetch Record based on meta key dates
- How to show optimized list of posts with all their attachment images
- how to make members list directory through wordpress post custom meta key.
- How do I query for posts by partial meta key?
- Large AND OR query timing out
- get_post_meta slowing down my page load (in a plugin)
- New WP_Query loop in admin causes problems
- echo a specific meta_key queried through a custom post
- How to increase load time of an archive/search page (WP_Query)
- WP_Query Attachment adds additional attachment count and need to link attachment to post url
- get_post_meta in WP_Query
- Which is faster wpdb & get_row or wp_query & ge_post_meta?
- Hide posts with meta key in WP_Query
- Filter posts by comparing custom meta value against postdate
- WordPress query posts with multiple post_meta data
- WP_Query – Accessing MetaValue from Query Result
- search serialised meta_value for date value?
- How do I check if an article is popular this week?
- Why having more than 10 clauses in WP_Query results in some outputs being dropped?
- Woocommerce: order posts by meta key
- Order WP_Query results by meta key value in custom query
- How can I update post meta inside a WP_Query loop or the WordPress loop?
- Nested array issue in meta_query
- wp_query get attachments in larger size
- Display post meta conditionally based on it’s value
- Creating attachments archive in tags and categories
- Filtering by multiple conditions in the loop
- Sort by custom field that is an array?
- Orderby two meta fields not working
- Display count number of posts with the same specific meta_key meta_value
- Ignore image urls in wp_query search
- Query posts by searching for a string in a meta field