Home Forums General Issues update_field() returned true/false not reliable?


update_field() returned true/false not reliable?

  • Documentation says:
    True on successful update, false on failure.

    However, I get false even though update is successful?
    I know that the result returns false if the old value and new value is equal, but in my case, it returns false even if:
    1) old value !== new value
    2) I see it updates just fine

    I tried one of the examples in the documentation :

    $selector = "job_salary";
    $value = array(
            "is_negotiable"   => "true",
            "depends_on_experience"   => "false"
    $result = update_field( $field_key, $value, $post_id );

    However, it returns false if this specific format is used.
    I can’t use update_sub_field since I am not in a loop; I am working with the REST API’s register_rest_field() update callback.

    Version: ACF 5.8.2

  • So, the issue here is that you’re using a repeater field.
    The repeater meta key is job_salary and it contains the number of rows in the repeater. Assuming the repeater already has 1 row and you are updating that row, it still has 1 row so no change has been made to the meta value of repeater field even if sub fields have been changed.

    I’m not sure I know of any way around this.

    You could attempt to call update_field for the sub fields using their actual meta key, but I really don’t know if this will work.

    update_field('job_salary_0_is_negotiable', 'true', $post_id);
    update_field('job_salary_0_depends_on_experience', 'false', $post_id);

    However, I do not know that this will work and even if it does I know that it will not work if the repeater in question will be updated correctly, especially if the repeater does not already have a value.

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

The topic ‘update_field() returned true/false not reliable?’ is closed to new replies.