Okay. Still wrestling with this code. I’ve tested this code with serialized and non-serialized post meta.
This code works perfectly fine with non-serialized meta. I go into Quick Edit, update the field and voila – the field is updated and displays correctly in the Admin List. So far so good.
// BEGIN SAVE THE QUICK EDIT DATA +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
add_action( 'save_post','rachel_carden_save_post', 10, 2 );
function rachel_carden_save_post( $post_id, $post ) {
// don't save for autosave
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
return $post_id;
// dont save for revisions
if ( isset( $post->post_type ) && $post->post_type == 'revision' )
return $post_id;
switch( $post->post_type ) {
case 'pattern':
// release date
// Because this action is run in several places, checking for the array key keeps WordPress from editing
// data that wasn't in the form, i.e. if you had this post meta on your "Quick Edit" but didn't have it
// on the "Edit Post" screen.
if ( array_key_exists( 'pattern_company', $_POST ) )
update_post_meta( $post_id, 'wpcf-own-pattern', $_POST[ 'pattern_company' ] );
break;
}
}
// END SAVE THE QUICK EDIT DATA +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
'
Now I take that same EXACT code but attempt to use it with serialized data. I go into quick edit, update the item and voila - it now shows nothing in the targeted information - in this case, the id of the gravity form is now blank.
'// BEGIN SAVE THE QUICK EDIT DATA +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
add_action( 'save_post','rachel_carden_save_post', 10, 2 );
function rachel_carden_save_post( $post_id, $post ) {
// don't save for autosave
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
return $post_id;
// dont save for revisions
if ( isset( $post->post_type ) && $post->post_type == 'revision' )
return $post_id;
switch( $post->post_type ) {
case 'product':
// release date
// Because this action is run in several places, checking for the array key keeps WordPress from editing
// data that wasn't in the form, i.e. if you had this post meta on your "Quick Edit" but didn't have it
// on the "Edit Post" screen.
if ( array_key_exists( 'ai_gravityforms', $_POST ) )
$gravity_form_data = get_post_meta( $post_id,'_gravity_form_data');// grab the current serialized array in the database
$gravity_form_data[0]['id'] = '10'; // replace the id in the serialized array with some test data
//$gravity_form_data[0]['id'] = '$_POST[ 'ai_gravityforms' ]; this is what I really want to grab
update_post_meta( $post_id, '_gravity_form_data', $gravity_form_data );
break;
}
}
// END SAVE THE QUICK EDIT DATA +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
When I test the following in the footer of page:
$gravity_form_data = get_post_meta( get_the_ID(),’_gravity_form_data’);
I can do a var_dump and see all the post meta for the particular product page that I’m on.
I can also replace the id by
$gravity_form_data[0][‘id’] = ’10’;
This all works but not inside the above function.
So the bottom line: How do I update serialized data when being processed via Quick Edit.