https://kriesi.at/support/topic/masonry-gallery-how-to-sort-by-random/
This topic is unfortunately closed, but the solution provided in it doesn’t work anymore after recent updates :/
Hi iheartwine!
When you edit the shortcode scroll down and you’ll see the “Order by” option which you can set to “Random”. This was added in one of the later Enfold versions.
Best regards,
Elliott
Hello Elliot and Dude,
the solution works for me but I cannot use it for only a certain gallery. It would affect all galleries.
So how can I randomly sort only one gallery? (e.g. with a custom_class)
add_filter('avia_masonry_entries_query', 'avia_random_image_query', 10, 2);
function avia_random_image_query($query, $params)
{
if(!empty($query['post_mime_type']) && $query['post_mime_type'] == 'image')
{
$query['orderby'] = "rand";
}
return $query;
}
Kind regards Axel
Hi,
You might want to add some conditional tags to filter the pages where you want it to apply, please refer to the wordpress codex: https://codex.wordpress.org/Conditional_Tags
Let us know if this helps :)
Best regards,
Nikko
Thanks for your quich reply Nikko.
But the two galleries are one the same page. Only one of them should randomly display. Therefore I need to filter an id or similar. Is this possible?
Or maybe a custom class?
Kind regards Axel
Hi Axel,
I see that’s pretty complicated though it’s possible, it would take some time to do it and outside the scope of our support. :(
Best regards,
Nikko
Should be able to set a class or ID to the section where your gallery is and with some creative conditionals targeting said class or ID, you should be able to do this. I haven’t tried, but in theory it should be more than possible that way.