Support

Account

Home Forums ACF PRO Gallery outputs images in opposite order (WPML)

Solving

Gallery outputs images in opposite order (WPML)

  • I have a gallery field that I have translated with WPML. On the back end the images are ordered/shown correctly in both languages.

    On the frond end the default/main language is showing the images in the right order, but the translation is showing them in the opposite order.

    Any suggestions?

  • Hi @eaglejohn

    It seems that the translated gallery saved in opposite order. I believe you can reverse the order by using the array_reverse() function like this:

    $images = array_reverse( get_field('gallery') );

    I hope this helps 🙂

  • Hi James, thanks for your answer. But wouldn’t that output the gallery in the main language in the wrong order then? So basically the problem will still exist?

  • Hi @eaglejohn

    I believe you can check the current language by using the ICL_LANGUAGE_CODE constant. This page should give you more idea about it: https://wpml.org/documentation/support/wpml-coding-api/. So, I think you can do it like this:

    if (ICL_LANGUAGE_CODE == 'en') {
        $images = get_field('gallery');
    } else {
        $images = array_reverse( get_field('gallery') );
    }

    Hope this helps 🙂

  • This would help indeed, but it’s not very flexibel if another language will be added to the website. I’m trying to figure out if this is an ACF or WPML bug. I know both plugins weren’t best friends in the past. Maybe they’re not still?

  • Hi @eaglejohn

    I believe the plugin author has added some compatibilities with WPML so they should have a better compatibility. The fact that the field is translated without error shows it.

    The issue you have is weird, though. Could you please check the entries in the database for both master and translated posts? You can check the custom field in the “wp_postmeta” table.

    Also, could you please check this page: https://www.advancedcustomfields.com/resources/multilingual-custom-fields/?

    Thanks!

  • I have this same issue, it’s the weirdest thing. I am running latest ACF and WPML as of Oct 2018. Was there any resolution besides telling it to reverse the order?

    Additionally, in the DB, it’s correct for all of the translations and matches the default language.

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

The topic ‘Gallery outputs images in opposite order (WPML)’ is closed to new replies.