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);
            $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;