Support

Account

Home Forums Add-ons Repeater Field acf_form not saving repeater correctly to postmeta table

Solving

acf_form not saving repeater correctly to postmeta table

  • Hello!

    I’ve been using repeater fields and acf_form in the front end for years and I’ve run into a new error I can’t solve.

    When I save my post in the WP backend the repeater gets saved correctly to the postmeta table:

    (meta_key => meta_value)
    my_repeater_name => 2
    my_repeater_name_0_sub_field_1 => valueA
    my_repeater_name_0_sub_field_2 => valueB
    my_repeater_name_1_sub_field_1 => valueC
    my_repeater_name_1_sub_field_2 => valueD
    (etc…)

    However, when I try to edit the repeater in the front end using an acf_form, the page redirects properly however the only change to the database is that the value of my_repeater_name is updated from the integer number of rows, to a serialised string:

    a:2:{i:0;a:8:{s:19:"field_57b955e362542";s:5:"testline1";s:19:"field_57b955f962543";s:0:"";s:19:"field_57b9560162544";s:0:"";s:19:"field_57b9560a62545";s:0:"";s:19:"field_57b9562462546";s:0:"";s:19:"field_57b9563b62547";s:0:"";s:19:"field_57b9565462548";s:0:"";s:19:"field_57b9565d62549";s:0:"";}i:1;a:8:{s:19:"field_57b955e362542";s:6:"testline2";s:19:"field_57b955f962543";s:2:"23";s:19:"field_57b9560162544";s:0:"";s:19:"field_57b9560a62545";s:0:"";s:19:"field_57b9562462546";s:0:"";s:19:"field_57b9563b62547";s:0:"";s:19:"field_57b9565462548";s:0:"";s:19:"field_57b9565d62549";s:0:"";}}

    Is this error something that my (heavily customised) theme is doing, or is ACF going wrong somewhere?

    I’ve checked $_POST['acf'] in acf/save_post and it looks fine to me:

    array(2) {
      ["field_57b955b462541"]=>
      array(2) {
        [0]=>
        array(8) {
          ["field_57b955e362542"]=>
          string(5) "testline1"
          ["field_57b955f962543"]=>
          string(0) ""
          ["field_57b9560162544"]=>
          string(0) ""
          ["field_57b9560a62545"]=>
          string(0) ""
          ["field_57b9562462546"]=>
          string(0) ""
          ["field_57b9563b62547"]=>
          string(0) ""
          ["field_57b9565462548"]=>
          string(0) ""
          ["field_57b9565d62549"]=>
          string(0) ""
        }
        [1]=>
        array(8) {
          ["field_57b955e362542"]=>
          string(6) "testline2"
          ["field_57b955f962543"]=>
          string(0) ""
          ["field_57b9560162544"]=>
          string(0) ""
          ["field_57b9560a62545"]=>
          string(0) ""
          ["field_57b9562462546"]=>
          string(0) ""
          ["field_57b9563b62547"]=>
          string(0) ""
          ["field_57b9565462548"]=>
          string(0) ""
          ["field_57b9565d62549"]=>
          string(0) ""
        }
      }
      ["_validate_email"]=>
      string(0) ""
    }

    and I’m calling acf_form_head() before page load. This is the form I’m calling:

    acf_form(array(
    		'post_id' => $post_ID,
    		'fields' => array(
    			'my_repeater'
    		),
    		'post_type' => 'events',
    	));
  • This sounds like a very similar issue, however if I use the field key field_57b955b462541 in my acf_form it doesn’t fix the issue.

    support.advancedcustomfields.com/forums/topic/problems-manually-updating-a-repeater-field-via-code-on-a-newly-inserted-post/

  • Fixed! The issue was I was calling acf_form_head() in an action inside my functions.php page. Once I delete that call and then placed the call at the top of the .php file loading the page it now works magically (using the actual field key in the form was necessary too.)

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

The topic ‘acf_form not saving repeater correctly to postmeta table’ is closed to new replies.