After moving a post to the recycle bin, the Metabox values disappear when I restore the post

Asked

Viewed 54 times

3

I have a wordpress theme where in the posts I have some custom Metabox.

When moving the post to the recycle bin and retrieving it again, it does not return with the values of the filled Metabox

What can it be?

1 answer

1


You are going through the same problem described in that matter (in English).

It’s probably a bug on the theme caused because the function save_post is called without the data of the post when the item is sent to the bin.

As described in the link above, the solution is to add a condition in the save function not to save the meta-data in this case.

Example taken from the link, which you should adapt in your theme:

function wpg_save_testimonial_author($post_id) {
  global $post;
  if (!wp_verify_nonce($_POST['testimonial_author_noncename'], plugin_basename(__FILE__).$post->ID)) {
    return $post->ID;
  }
  if(defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
    return $post_id;
  }
  if(defined('DOING_AJAX')) {
    return;
  }
  if(!current_user_can('edit_post')) {
    return $post->ID;
  }
  if($post->post_type == 'revision') {
    return;
  }
  update_post_meta($post->ID, 'testimonial_author_name', $_POST['testimonial_author_name']);
  update_post_meta($post->ID, 'testimonial_author_link', $_POST['testimonial_author_link']);
}
add_action('save_post', 'wpg_save_testimonial_author');

Browser other questions tagged

You are not signed in. Login or sign up in order to post.