Support

Account

Home Forums ACF PRO Values cannot be saved no matter what I do

Solving

Values cannot be saved no matter what I do

  • I have hit a wall and spent a bunch of hours trying to solve this bug. I have a version of the website that I run locally and all the fields there work as they should. I can easily update, delete, change and save data that goes through ACF.

    However, on the staging website which is run on Amazon Lightsail, I have the exact same theme and fields but I cannot save some of them. When I enter values and hit “Update”, the values are cleared. It is not a problem with the code because in that case this wouldn’t work in the local env as well.

    I have tried changing the names of the fields, creating new pages (the same set of fields does not work again), turning off all plugins, using the new WP editor, using the old WP editor, updating the plugins, updating WP, sacrificing a goat to the gods of saving data in ACF fields and sprinkling holy water on the computer. Nothing. Works.

    What am I missing here? Any guidance is appreciated.

    WordPress 5.6.2
    ACF PRO 5.9.5

  • It sounds like you are having an issue with the php setting max_input_vars or a related php setting.

    How many fields are there? What is this setting on the server?

  • Thanks, but that didn’t solve my problem, unfortunately.

  • also experiencing the same issue out of nowhere. what’s stranger is that this is on a multisite, with dozens of sites. all but one function. they use the same themes, they use the same servers, databases, etc. the issue is only on one of the sites. i looked into the max_inputs_vars and added php.ini directives for that.

    no luck.

    old values get erased, new custom fields don’t get saved.

    this only happens on one specific site of the multisite, all other sites using the same theme don’t have that problem.

    i tried to switch themes on the problematic site, and it saved.

    i am not sure where to look exactly to solve this problem, although I understand it may be something we did in our custom theme that’s breaking – if you have a way to help me find out what is breaking i can try to fix it 😉

    thanks!

    k

  • Going to be honest, it will be very hard for me to help without being about to constantly reproduce. But some questions.

    Does this happen when editing every post or just when editing some posts?

    Does this happen every time you save the post or does saving work part of the time?

  • John,

    Thanks for the swift reply and all the work you do on ACF. Been following you for a while.

    This happens on all posts that have a repeater. Regular fields work fine. It happens 100% of the time on those posts. Old values get erased if they existed before (specifically relationship fields).

    It happens only on one site even though the other sites use the same theme and share the same functions.php and server config.

    This just started happening – possibly related to the latest upgrade but not sure.

    How can I help you help me find out what’s up?

  • how can i do a json / other dump of the save post to see the data that ACF is receiving?

  • The first thing I would do is to see if the data is actually getting to the server. Why, because I haven’t a clue where to start so I would start at the beginning.

    I would open up the file /wp-admin/post.php and at the top of the file I would add

    
    // this if will make sure this is only run for you
    // change the user ID value to yours
    if (get_current_user_id() == 1) {
      // see what's in $_POST if it's not empty
      if (!empty($_POST['acf'])) {
        echo '<pre>'; print_r($_POST['acf']); die;
      }
    }
    

    The above should print out what is being sent to ACF and halt execution. Then I would compare what is there with what should be there to see if the fields in questions are submitted.

  • ok – i was able to eliminate some noise from the error_log, and I can identify this line item that may be related to the issue, which turns out happens on all NEW fields for ALL sites using THIS theme, not another.

    the only log that appears on save of the post is this:

    
    [Thu Feb 25 13:47:15 2021] [warn] [client 213.32.4.94] mod_fcgid: stderr: PHP Warning:  preg_match() expects parameter 2 to be string, array given in /var/www/vhosts/inovie.fr/httpdocs/wp-includes/class-wp-block-parser.php on line 417, referer: https://labosud.fr/wp-admin/post.php?post=7912&action=edit
    [Thu Feb 25 13:47:15 2021] [warn] [client 213.32.4.94] mod_fcgid: stderr: PHP Warning:  strlen() expects parameter 1 to be string, array given in /var/www/vhosts/inovie.fr/httpdocs/wp-includes/class-wp-block-parser.php on line 489, referer: https://labosud.fr/wp-admin/post.php?post=7912&action=edit
    

    …which comes from a core file… so not sure what to do with that.

    thanks again for your help!

    Kaz

  • further – this error ☝🏼 only occurs if I touch the ACF field in question, (which I already tried to duplicate and rebuild, no luck) not if I touch the content or other areas.

    Kaz

  • just saw your reply, sorry!

    i added two items from the relationship field:

    Array
    (
        [field_5f3fc9e272878] => Array
            (
                [0] => 7912
                [1] => 7897
            )
    
    )
    

    and that seems to be a good thing 😉

    let me know what you think and thanks as always,

    Kaz

  • ok – update. for me, this ticket on another plugin helped me :

    I had recently added some code to that particular theme because (long story) this is a multisite, and in multisites there are restrictions that prevent non super-admins from adding iframes or embeds so I created a field for code with ACF that I run through this filter:

    // remove the html filter on all ACF fields
    add_filter('acf/allow_unfiltered_html', 'mfo_acf_allow_unfiltered_html_all_fields');
    function mfo_acf_allow_unfiltered_html_all_fields() {
        return true;
    }
    // re-apply filter to non-code fields
    add_filter('acf/update_value', 'mfo_acf_disallow_unfiltered_html_non_code_field', 1, 3);
    function mfo_acf_disallow_unfiltered_html_non_code_field($value, $post_id, $field){
            if(
                $field['type'] !== 'acf_code_field'){
                $value = wp_kses_post($value);
    		}
    
        return $value;
    }
    

    this is what breaks the ACF relationship add…

    the function wp_kses_post mentioned in the link above put me on the right track. so now, I need to find a way to add that filter without breaking ACF… any suggestions? I can open a different thread if you prefer.

  • I used your function, @hube2

    function acf_wp_kses_post($data) {
      if (!is_array($data)) {
        return wp_kses_post($data);
      }
      $return = array();
      foreach ($data as $index => $value) {
        $return[$index] = acf_wp_kses_post($value);
      }
      return $return;
    }
    

    and replaced it in the filter above. seems to work!

    you guys are amazing, thank you 🙂

  • @g0ldmund & @airplanenoise

    Are these fields that are not saving inside of ACF blocks?

Viewing 15 posts - 1 through 15 (of 15 total)

You must be logged in to reply to this topic.