Home › Forums › Add-ons › Gallery Field › 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 3.1.9.5
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’]; ?>” />
</div>
<?php endforeach; ?>
</div>
<?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 :
<?php
$galerie = get_field('galerie');
print_r($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 🙂
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:
USING THIS
$id = icl_object_id($v['wp']->ID, 'property', true, ICL_LANGUAGE_CODE);
$img = get_field('galeria',$id);
AND THIS
$id = icl_object_id($v['wp']->ID, 'property', true, "en");
$img = get_field('galeria',$id);
OR THIS
$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.
UPDATE:
The trick from webloft here: http://support.advancedcustomfields.com/forums/topic/acf-gallery-vs-wpml/ works for me.
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:
https://wpml.org/forums/topic/wpml-cms-and-acf-gallery/
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?
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);
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;
}
Wow how did you give this solution one day before I needed it. That’s brilliant, and works like a charm!
The topic ‘Wrong Gallery order in other languages’ is closed to new replies.
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.