Support » Plugins » Hacks » Custom Field Data Lost upon trashing?

  • Resolved wpgods


    I’ve created a custom post type with 2 custom fields attached to it… When I create a post of this type and fill in the custom fields, the data is, in fact, saved to the db… However, if I trash one of them, then that post’s custom fields data is deleted from the database.

    I thought trashing was just supposed to basically change the post_status to “trash” so it’s out of view unless you actually delete it permanently?

    If that’s the case, why am I losing my custom fields data when I trash an item?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Here’s all the relevant code for the above question:

    [Code moderated as per the Forum Rules. Please use the pastebin]

    The custom post type doesn’t support the “title” portion of posts, so it’s not included as one of the columns in the edit posts page. Therefore, I had to hack my own version of the row_actions() function to enable the edit/quick edit/trash/view links when each post is hovered.

    All of the functionality works as it should… Except that the “testimonial author” and “attribution link” values are deleted from the database when moving a post to the trash. No idea why…

    It seems that the action “save_post” gets fired when moving a post into the trash… So my save method was being run with no $_POST data to process.

    The solution wound up being to add a nonce to the save process for the custom fields, this way they don’t get overwritten when a post is moved to the trash since the nonce is sent with the $_POST data.

    A good idea anyway, not sure why on earth I didn’t think of it sooner.

    [Code moderated as per the Forum Rules. Please use the pastebin]

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Custom Field Data Lost upon trashing?’ is closed to new replies.