$15
Quick Edit/Bulk Edit clears all custom field values!
I've searched for a solution for this problem on forums etc. but I just can't find a solution. This looks like a bug but I think it was, more people should have encountered it, and since it is rather serious, it should've been fixed in WP 3.01 (which is the version I am using).
The problem is the following;
I've set-up several custom write panels for editing posts. Several custom fields are saved with the post. This includes a reference to a video file, video thumbnail among other custom data.
When the post is saved/updated via the Edit Post screen there is no problem. The custom fields are saved as they should. However, when a post is edited using the Quick Edit or Bulk Edit feature (e.g. changed the category, adding some tags), all the custom field values of that post are deleted!
First I figured a "workaround" by just hiding the Quick Edit option (via CSS) on the post list, but this does not work for Bulk Edit. I can't figure out what I am doing wrong here and I need some solutions quick!
What might be relevant here is the code I use to save custom field values of posts:
function xx_save_metabox( $post_id ) {
// check if this is autosave
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE)
return $post_id;
if( !current_user_can( 'edit_post', $post_id ) ) // check permissions
return $post_id;
$fields = array(
'xx_stdvideo_url',
'xx_hdvideo_url',
'xx_thumb_url');
foreach( $fields as $field ) {
if( isset($_POST[$field]) && $_POST[$field] != '' )
update_post_meta( $post_id, $field, $_POST[$field] );
else
delete_post_meta( $post_id, $field, get_post_meta( $post_id, $field, true ) );
}
}
add_action( 'save_post', 'xx_save_metabox' );
(the actual function prefix is replaced by xx)
jedw | 08/18/10 at 10:21am
| Edit
(3) Possible Answers Submitted...
-
Last edited:
08/18/10
10:26amOleg Butuzov says:if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest'){
return $post_id;
}
one more rulePrevious versions of this answer: 08/18/10 at 10:26am
- 08/18/10 10:35am
jedw says:The problem persists after adding this rule. Considering your quick response you've dealt with this particular problem before, am I missing something here?
function xx_save_metabox( $post_id ) {
// check if this is autosave
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE)
return $post_id;
if( !current_user_can( 'edit_post', $post_id ) ) // check permissions
return $post_id;
if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest')
return $post_id;
$fields = array(
'xx_stdvideo_url',
'xx_hdvideo_url',
'xx_thumb_url');
foreach( $fields as $field ) {
if( isset($_POST[$field]) && $_POST[$field] != '' )
update_post_meta( $post_id, $field, $_POST[$field] );
else
delete_post_meta( $post_id, $field, get_post_meta( $post_id, $field, true ) );
}
}
add_action( 'save_post', 'xx_save_metabox' );
- 08/18/10 10:40am
jedw says:Can you elaborate on the code you suggested? What does it?
- 08/18/10 11:51am
Oleg Butuzov says:yeas your right i had got this issue before
the code you insert is correct one. what it dose...
when post saved (from ajax query) its hook your triger but there is no POST data that you requeire... thats why its delete values from custom fields. because thay not found.
what i did i just provide additional rule that if thats a ajax request we only return the post_id thats all...
can you confrm that this
$fields = array(
'xx_stdvideo_url',
'xx_hdvideo_url',
'xx_thumb_url');
custom fields are lost after the ajax saving? because thats quite intresting stuff in this case. - 08/18/10 11:55am
Oleg Butuzov says:all the custom field values of that post are deleted!
all or just a that values that you had add?
'xx_stdvideo_url',
'xx_hdvideo_url',
'xx_thumb_url'
- 08/18/10 10:35am
-

Last edited:
08/18/10
10:31amJonah Schulte says:It seems like the part where you delete the post meta if it's not set in the $_POST array might be causing the issue...
delete_post_meta( $post_id, $field, get_post_meta( $post_id, $field, true ) );
Maybe try without that and see if the problem persists? I'm not sure why that's there, as you can just delete the post meta on the edit screen if desired...Previous versions of this answer: 08/18/10 at 10:31am
-

Last edited:
08/22/10
9:19amUtkarsh Kukreti says:
function xx_save_metabox( $post_id ) {
// check if this is autosave
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE)
return $post_id;
if( !current_user_can( 'edit_post', $post_id ) ) // check permissions
return $post_id;
$fields = array(
'xx_stdvideo_url',
'xx_hdvideo_url',
'xx_thumb_url');
foreach( $fields as $field ) {
if( isset($_POST[$field]) && $_POST[$field] != '' )
update_post_meta( $post_id, $field, $_POST[$field] );
else if( isset($_POST[$field]) )
delete_post_meta( $post_id, $field, get_post_meta( $post_id, $field, true ) );
}
}
add_action( 'save_post', 'xx_save_metabox' );
This question has expired.
Current status of this question: Completed




