#57147 closed defect (bug) (invalid)
custom post types no longer saving/retrieving correctly
Reported by: | wellituser | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | major | Version: | 6.1 |
Component: | Posts, Post Types | Keywords: | |
Focuses: | Cc: |
Description (last modified by )
Following the 6.1 update my custom post type feature is no longer retrieving the meta data for the saved post in the WordPress dashboard area. It only stores the title and does not save/retrieve any custom field data. Here are the opening lines from each key part:
*** register_post_type( 'cal_loans', array() *** function cd_meta_box_cb() { global $post; $values = get_post_custom( $post->ID ); *** add_action( 'save_post', 'cd_meta_box_save' ); function cd_meta_box_save( $post_id ) { ***
This was working previously up to 6.0.3
Change History (5)
#3
@
23 months ago
I worked out what the issue was:
This line needs to change so you're checking the edit_post capability against the specific post you're trying to save.
if( !current_user_can( 'edit_post' ) ) return;
So that line above becomes this:
if (!current_user_can('edit_post', $post_id)) return;
This seems to be required after the WordPress v6.1 update.
#4
@
22 months ago
- Keywords reporter-feedback removed
- Milestone Awaiting Review deleted
- Resolution set to invalid
- Status changed from new to closed
Thanks for the follow-up!
Yes, that is correct, these capabilities check for a particular post and do require a post ID:
current_user_can( 'delete_post', $post_id )
current_user_can( 'edit_post', $post_id )
current_user_can( 'read_post', $post_id )
current_user_can( 'publish_post', $post_id )
[53408] / #44591 aimed to address this in a consistent way. Performing these checks without passing in a post ID is not supported and could only work by accident. See the discussion in #56962 for more details.
Hi there, welcome to WordPress Trac! Thanks for the report.
Could you share a bit more complete example to reproduce the issue on a clean install?