Support

Account

Home Forums General Issues Add value to url field inside repeater

Solved

Add value to url field inside repeater

  • Hi,

    I have some problem. I followed the documentation and used update_field with array for each row inside array for the value associate with the repeater field. It isn’t working. The value inside the table is a json and don’t look really that’s supposed. It’s simple. I received value from a form in ajax. I create a new post with the custom post type. After, with the ID, I associate the value for each advanced custom field. I have approx 25 fields. All is working except the url field inside repeater field.

    Thank you !

  • Hi @v3madmin

    Did you use the field name instead the field keys for the repeater in the update_field() function? If you did, could you please use the field keys instead (something like “field_1234567890abc”)?

    If you have done that but still have the issue, could you please share the code you used and the JSON or XML export of your field group?

    Thanks!

  • Hi James,

    I just tried. I explain the information.
    The repeater field name is cc_loanrequest_last30daysbankstatement.
    The url field inside repeater is cc_loanrequest_last30daysbankstatement_file.
    cc_loanrequest_last30daysbankstatement is field_571fb7b99ffd3.

    I created a array like this :

    $arrayvalues = array(array(“cc_loanrequest_last30daysbankstatement_file” => “http://www.google.ca”));
    update_field(“field_571fb7b99ffd3”, $arrayvalues, $postid);
    update_field(“cc_loanrequest_last30daysbankstatement”, $arrayvalues, $postid);

    I used the field key and field name. Look what is in the table.
    meta_key is cc_loanrequest_last30daysbankstatement_file
    meta_value is a:2:{i:0;a:1:{s:43:”cc_loanrequest_last30daysbankstatement_file”;s:96:”http://www.google.ca”;}}

    Thank you for your help.

  • Hi @v3madmin

    I’ve just tested it on my end, and it was working as it should be. One issue that I see with your setup is that you have a very long name for your repeater and its subfields. Could you please rename it to something shorter? This page should give you more idea about it: https://www.advancedcustomfields.com/resources/field-value-wont-save/.

    Also, could you please make sure that no other function in your plugins and theme caused it? To do it, you can try to reproduce the issue on one of the WordPress’ stock themes (like Twenty Fifteen) with only ACF activated.

    I hope this helps 🙂

  • Hi James,

    I reduce the length of sub field. I created a log file to see the field name and data before update. Look at this :

    cc_loanrequest_last30daysbankstatement
    Array
    (
    [0] => Array
    (
    [file] => http://www.domainname.dev/loanrequest/?file=213/cc_loanrequest_last30daysbankstatement_1.
    )

    [1] => Array
    (
    [file] => http://www.domainname.dev/loanrequest/?file=213/cc_loanrequest_last30daysbankstatement_2.txt
    )

    )

    The information in table look like this :

    meta_key = _cc_loanrequest_last30daysbankstatement
    meta_value =

    meta_key = cc_loanrequest_last30daysbankstatement
    meta_value = a:2:{i:0;a:1:{s:4:”file”;s:96:”http://www.domainname.dev/loanrequest/?file=212/cc_loanrequest_last30daysbankstatement_1.txt”;}i:1;a:1:{s:4:”file”;s:93:”http://www.domainname.dev/loanrequest/?file=212/cc_loanrequest_last30daysbankstatement_2.”;}}

    I will try a fresh install…

  • Hi James,

    Ok. I had 2 problems. Too long field name and the use of field key instead of field name. But, for me, it’s a bug. I use always field name but not working with repeater… seem buggy. In my form, I use the field name for the input name. So, I use the $_POST key and $_FILES key to update field.

    It’s important to solve this situation…

    Thank you !

  • Hi @v3madmin

    Did changing the name and using the field key fixes the issue?

    You need to use the field key for the new value because the reference entry is not created yet. Please take a look at this page to learn more about it (under the Basic (field key) section): https://www.advancedcustomfields.com/resources/update_field/.

    If changing the name and using the field key were not working for you, could you please share your code so I can test it out on my end?

    Thanks 🙂

  • Hi James,

    In fact, my problem is solved. It was a too long fieldname because of the field and subfield. It’s working very nicely with field key. What I wanted to say it’s why associate a field name if I can’t use it. As I said, I used the input name in $_POST and $_FILES as field name. I created a loop foreach and I used the key ($key => $value) as the field name because it’s natural more than field key. I needed to go in table and look the field key in table associated with the field name. After, created a conditional to associate the right field key with field name. So, for me, it’s a wrong use.

    It’s my opinion.

  • Hi @v3madmin

    You can use the field name if the value has been initialized in the database at least once. You can do it by saving the post from the backend editor or front end form. But if the value is not initialized yet, you need to use the field key so ACF knows which field you want to add since you can have different custom fields with the same name. It will prevent the confusion in the system.

    But if you still think that this is a bug, you can create a new ticket from the following link so it can be passed directly to the plugin author: https://support.advancedcustomfields.com/new-ticket.

    I hope this makes sense 🙂

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

The topic ‘Add value to url field inside repeater’ is closed to new replies.