Home › Forums › Add-ons › Gallery Field › Wrong Gallery order in other languages › Reply To: Wrong Gallery order in other languages
Hello,
Building on the previous solution with a more generic one, dropping this in our functions.php file fixed all galleries on the site:
add_filter( 'acf/format_value/type=gallery', 'fix_gallery_order', 100, 3 );
function fix_gallery_order($value, $post_id, $field){
$order = get_field($field['name'], $post_id, false);
if(is_array($order)){
$order = array_map(function($id){
return apply_filters('wpml_object_id', $id, 'attachment', true);
}, $order);
usort($value, function($a, $b) use ($order){
return array_search($a['ID'], $order) - array_search($b['ID'], $order);
});
}
return $value;
}
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.