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
}
}
}
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.