Home Forums Add-ons Gallery Field Wrong Gallery order in other languages


Wrong Gallery order in other languages

  • I have a gallery in options page. In the main language displays the correct order in front page. The problem is that in secondary languages it shows images in alphabetic order. Should display images in custom gallery order as usual.

    I’m using ACF PRO 5.2.5 and WPML

    This also happen with the gallery in a page. I moved to options in order to solve it but didin’t work.

    This is the PHP code for the gallery.

    <?php //galeria
    $images = get_global_option(‘logos_clientes’);
    if( $images ): ?>

    <div class=”logosclientes”>

    <?php foreach( $images as $image ): ?>
    <div class=”logo”>
    ” alt=”<?php echo $image[‘alt’]; ?>” />
    <?php endforeach; ?>


    <?php endif; ?>

  • Hi @vueloiv

    Could you also post your get_global_option function?
    The issue would be in there somewhere I believe.

  • Hello, i have the same problem :

        $galerie = get_field('galerie');

    In my main language front page order is equal to admin order, and in my other languages order is not equal to admin, order changes are ignored.

  • Hi @bnbc

    So you’ve tried changing the order on a translated page and it still shows the images in alphabetical order instead?

    If possible, could you try switching your main language and see if the issue appears on the old main language and disappears on the new main language?

  • Yes for your first point.

    I did your test, i passed my main language to EN and it’s ok for all languages ! the issue disappears and order is ok for all.

    But when i reset my main language to FR the EN order is again not ok.

  • Ah okay.. interesting. That means the issue lies in having a different main language than english.

    And you’re using the latest version of WP, WPML and ACF? ACF 5 or 4?

  • Yes that’s it.

    WP (4.2.3), WPML (3.2.2) and ACF (5.2.8) are up to date.

  • I’ll include @elliot in the conversation so he can determine if this is a bug that should be fixed in ACF 🙂

  • Hello, some news with this issue ?

    Thks !

  • Hi, i have some news and manual fix !

    The problem is when i duplicate a post with a gallery field and i use the button “Overwrite with FR content”, images in the gallery (in EN post) are the FR images and not the EN duplicated images.

    So to fix the issue i have to delete the images in the gallery and click on the “Add to gallery” button to select again the good images (EN duplicated images).

    Do you think this action can be automated ? by ACF or WPML ?

    Sorry for my english…

  • Hi @bnbc

    Ah I see so that’s the issue. It’s hard to say where the “blame” falls exactly but my personal opinion is that WPML when copying content should also copy the images to the language and fix this themselves.

  • Same problem here! Need to talk with WPML team?

    In my case calling to field and forcing original post no solved the problem:


    $id = icl_object_id($v['wp']->ID, 'property', true, ICL_LANGUAGE_CODE);
    $img = get_field('galeria',$id);


    $id = icl_object_id($v['wp']->ID, 'property', true, "en");
    $img = get_field('galeria',$id);


    $id = icl_object_id($v['wp']->ID, 'property', true, "es");
    $img = get_field('galeria',$id);

    In this 3 cases, order is correct in main language (es) and incorrect in others.

  • Hi Carlos

    Yeah it works since he’s fetching the images from the main language instead. A decent workaround but it does require some unnecessary stuff going on and makes translating alt tags etc hard to do.

    My opinion is still to nag at the WPML team to fix the duplication process so it includes images since that seems to be the root of the problem.

  • Thanks for your reply, but seems they aren’t interested in this integration:

    For now, this works for me, although I know that’s not the optimal solution

  • Well there you go. In my experience that’s generally the response you get from WPML.. not their biggest fan tbh 🙂

    Perhaps checking to translate media in WPML settings makes some magic happen?

  • Hi,

    I have the same proble. Any news about this?


  • Hello, I have the same problem.

    The point is that the translated gallery don’t change the order even manually.

  • Hello,
    for everyone who still got the problem of wrong order output on not-default-language, you might could try this. It worked for me.

    // 3rd parameter (false) is important to prevent pre-formatting 
    $images = get_field('media_gallery', false, false);
    // the foreach output now gets the right order and gives the image-IDs
    foreach( $images as $image_id ){
      // get imageURL by ID
      $image_url = wp_get_attachment_url( $image_id );

    this code worked for me in default language and every other one.
    I think that the pre-formatting by the “get_field”-function might create the order mess up.

  • 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;
  • Wow how did you give this solution one day before I needed it. That’s brilliant, and works like a charm!

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

The topic ‘Wrong Gallery order in other languages’ is closed to new replies.