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?
- Is there a way to extend WP_query so Custom Post Types can have properties?
- 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
- WP-CLI How to generate a list of posts with corresponding meta values
- What is an efficient way to query based on post_meta?
- WP_Query not working as expected for attachments and custom meta_query
- Group posts by meta_key
- Get attached media only
- WordPress altering my custom query, How to fix it?
- 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 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 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?
- 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
- Inserting serialized value into wp_postmeta using update_post_meta
- How to do meta_query for attachments?
- 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 make members list directory through wordpress post custom meta key.
- Large AND OR query timing out
- get_post_meta slowing down my page load (in a plugin)
- echo a specific meta_key queried through a custom post
- WP_Query Attachment adds additional attachment count and need to link attachment to post url
- Filter posts by comparing custom meta value against postdate
- WP_Query – Accessing MetaValue from Query Result
- 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?
- 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
- WP_Query: attachment image in “full” size?
- How can I build a query that returns all attachments of a page and it’s children pages?
- get all images from the wordpress media library with link to the post they are associated with
- How do i create a custom post query when the meta value is an array?
- Sort by price wpdb
- Meta query ignores multiple values of the key
- How to restrict add media library only to images of the same post family?
- Query against multiple locations within single custom post type post
- Look for string in posts and postmeta
- Query postmeta based on meta_value, return array of post_id
- update_post_meta() not updating
- I can’t get post based on its postmeta value and key
- Meta key in wp_query bug?
- WP Meta Query at depth 2
- wp_get_attachment_image not to get the post_thumbnaill
- WP_Query with child element
- Sort by meta key within same day
- Query All Attachments and Order by Parent Publish Date
- Sorting Posts with meta value not working
- WP_Query for attachments without duplicating post_parent and displaying tagged image
- WP Query to order posts by multiple meta fields
- Return a single custom post from multiple meta queries
- Using WP_Query to get attachment returns empty set
- How to query post ids liked by the Author
- loop through custom post types with meta data
- Query posts by meta value and sort by another meta key
- WP_Query by meta key not returning any posts
- Give attachments an archive page, and exclude unattached ones
- on attachment.php, how to display previous and next attachment links that follow the same order as a custom WP Query
- How to get posts that have certain meta key value and order based on another meta key’s value