Make WordPress Core

Opened 17 months ago

Closed 16 months ago

Last modified 15 months ago

#57147 closed defect (bug) (invalid)

custom post types no longer saving/retrieving correctly

Reported by: wellituser's profile wellituser Owned by:
Milestone: Priority: normal
Severity: major Version: 6.1
Component: Posts, Post Types Keywords:
Focuses: Cc:

Description (last modified by SergeyBiryukov)

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',


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)

#1 @SergeyBiryukov
17 months ago

  • Description modified (diff)

#2 @SergeyBiryukov
17 months ago

  • Keywords reporter-feedback added

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?

#3 @wellituser
17 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 @SergeyBiryukov
16 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.

#5 @JeffPaul
15 months ago

#57274 was marked as a duplicate.

Note: See TracTickets for help on using tickets.