I've only experienced this a few times: I have a plugin with many meta fields for pages and other post types. Very occasionally, the update_post_meta() function won't have any effect with just one field. the other fields work fine. This is after the field has worked several times but it just stops. If I go into my metaboxes.php code and change the field name (the meta_key) they start working again. What would cause this kind of "freezing up" behavior for postmeta?
Here's an example of the save function that I use:
in metaboxes.php:
function fws_meta_save( $post_id ) {
// Checks save status
$is_autosave = wp_is_post_autosave( $post_id );
$is_revision = wp_is_post_revision( $post_id );
$is_valid_nonce = ( isset( $_POST[ 'fws_nonce' ] ) && wp_verify_nonce( $_POST[ 'fws_nonce' ], basename( __FILE__ ) ) ) ? 'true' : 'false';
// Exits script depending on save status
if ( $is_autosave || $is_revision || !$is_valid_nonce ) {
return;
}
//list of fields to save *this is connected to another feature that handles post revisions and isn't related
$revision_field_array = Array(
'featured',
"type",
"resource_type",
"logo_header",
....more fields
);
foreach($revision_field_array as $field){
if( isset( $_POST[ $field ] ) ) {
update_post_meta( $post_id, $field, $_POST[ $field ] );
}
}
} add_action( 'save_post', 'fws_meta_save' );
So this save function works for all the fields except occasionally one field stops saving. When I click update in the page edit screen, It just shows the same value as before. I have debugged by doing something like this - for example the logo_header field stopped saving:
foreach($revision_field_array as $field){
if( isset( $_POST[ $field ] ) ) {
if($field == "logo_header"){
error_log("old value: " . (string)get_post_meta( $post_id, $field, true )[0]);
error_log("new value: " . $_POST[ $field ] );
}
update_post_meta( $post_id, $field, $_POST[ $field ] );
if($field == "logo_header"){
error_log("updated value: " . (string)get_post_meta( $post_id, $field, true )[0]);
} );
}
}
After attempted save, the log reads: [17-Feb-2019 19:36:36 UTC] old value: off [17-Feb-2019 19:36:36 UTC] new value: on [17-Feb-2019 19:36:36 UTC] updated value: off
so I can see the post contains the new value but it's not getting saved.
Some context: This is one blog on a multisite network with 20+ sites, running on WP Engine. PHP version 7.0 WP 5.0.3
I have added the following line to .htaccess to increase the max_input_vars in the post
php_value max_input_vars 10000