Support

Account

Home Forums Add-ons Repeater Field update_sub_field not working

Solving

update_sub_field not working

  • Hi.
    I have a Repeater Value which contains a Post Object as sub field 1 and a Number as sub field 2

    I’m trying to create a repeater entry (new row) by code in a specific post (ID: 2933). I want my first row to relate post 279 with a Number 1 as value

    update_sub_field(array('field_5422339bd5eab', 1, 'field_543afcf561f95'), 279,'2933');
    update_sub_field(array('field_5422339bd5eab', 1, 'field_543afcae61f94'), 1,'2933');
    

    I also tried leaving the field values like ‘1’ and ‘279’, also I tried changing the field keys by their field names, and changing ‘2933’ to 2933 but nothing working.

    What could be failing?

    Edit: I notice this works if the post already has a Repeater row. How can I get it work if the post don’t have any row yet?

  • I have the same issue. Both “update_field” and “update_sub_field” works fine if there is already rows, but not if it’s the first row you are adding to a new post.

  • I have same issue I need to update a sub_field value based in another subfield and I tried everything and is not working, row loop is fine but it did not update the subfield no matter the way i try ( name_fiel, array(repeater), key_field) nothing works.

  • Not sure if this help someone:

    In my case “update_sub_field()” fails to update POST_META table:
    It creates an additional record for the post without repeater name:

    _0_subfield
    _1_subfield
    _2_subfield

    and does’nt update the good records:

    repeaterName_0_subfield
    repeaterName_1_subfield
    repeaterName_2_subfield

    And from them it updates the wrong ones, “update_sub_field()” seems like the function fails to “add” repeater name to the meta_key, anyway I found a workaround:

    Use the core function “update_post_meta()” :

    update_post_meta( $post_id, “repeaterName_0_subfield”, “new value” );
    update_post_meta( $post_id, “repeaterName_1_subfield”, “new value” );
    update_post_meta( $post_id, “repeaterName_2_subfield”, “new value” );

    This function update values in custom fields in Post_Meta table.
    PD: If you need to know how many “rows” has your repeater you can use this:

    $number_rows = get_post_meta( $post_id, “repeaterName” );

    This works for me perfectly, I spend a lot of time struggling with update_sub_fiel(), hope there will be an update it soon.

  • facing the exact same problem.

    but cant use your update_post_meta solution because its a repeater in a repeater where i have to add a new row.

    i looked up in the database but the meta_key from the second repeater is = subrepeater_ and not repeaterName_0_subrepeater_0_subsubfield.

    so how can i refer to the right row in the repeater and add a field in the subrepeater?

  • Hi everyone.

    The issue here is that update_sub_field does exactly what it says. It updates an existing sub field but does not have the ability to create a new one.

    Have a look at my sample code here for a solution:
    http://support.advancedcustomfields.com/forums/topic/create-new-repeater-row-from-front-end-form/

  • i really appreciate your solution! i tried it and it works! thank you very much !

  • Great to hear πŸ™‚ @scisterna if you also find it to resolve your issues please mark it as an answer so future visitors may find it easily.

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

You must be logged in to reply to this topic.