Support

Account

Home Forums General Issues Comparing get_fields() with $_post['acf'] orders are flipped Reply To: Comparing get_fields() with $_post['acf'] orders are flipped

  • get_fields() returns fields in the order that they were created. get_fields() uses get_post_meta() to get the fields. There isn’t a way to order what is returned from WP when using this function.

    The order of $_POST[‘acf’] is the order that the fields appear in the form. There isn’t a way to set this order either as it is done by the browser.

    The way to check this is to loop through each $_POST[‘acf’] value and use the field key to get the old value instead of trying to get all of the fields at once and depending on them being in the same order, something like this.

    
    if (!empty($_POST['acf'])) {
      foreach ($_POST['acf'] as $field_key => $new_value) {
        $old_value = get_field($field_key, $post_id);
        if ($new_value != $old_value) {
          // do something
        }
      }
    }