The changing the sort options of WordPress plugin “NextGEN Gallery” doesn’t affect on the images of the gallery sorted by tags. To fix the bug, do the following changes in nextgen-gallery\lib\ngg-db.php


// Check for the exclude setting
$ngg_options = get_option('ngg_options');
$gal_sort = $ngg_options['galSort'];
$gal_sort_dir = $ngg_options['galSortDir'];
if ( $gal_sort_dir == 'RAND' ) {
   $order_clause = 'ORDER BY rand() ';
} elseif ( $gal_sort_dir == 'DESC' ) {
   $order_clause = ' ORDER BY t.'.$gal_sort.' DESC';
} else {
   $order_clause = ' ORDER BY t.'.$gal_sort.' ASC';

instead of

// Check for the exclude setting
$order_clause = ($order == 'RAND') ? 'ORDER BY rand() ' : ' ORDER BY ASC' ;

in the function find_images_in_list.

Getting the sort options from the database that is set in this function for not affecting on the work of other functions.


17 Comments on WordPress Plugin NextGEN Gallery Sorting Bugfix

  1. TFM says:

    Fix works perfect – thank you so much!

  2. Julia says:

    This didn’t work for me. Any idea why?

  3. Julia,

    Please write the versions of WordPress and the plugin “NextGEN Gallery” that you use and I’ll try top help you.

    Thank you.

  4. Joanne says:

    Thanks for posting this fix. I wondered if anyone corrected the sorting bug in next-gen gallery for the galleries by tag. Totallly awesome of you to post it — thanks it worked great just as you posted it.

  5. 13 says:

    This worked for me for the latest version of WordPress and NextGEN Gallery as of November 2011. Thank you so much!

  6. Joanne and 13, it is really great to help you!!!! :)


  7. Kees says:

    Thanks! Been struggling with this a while!
    Cant you persuade Alex to include this in the code 😉

  8. Hi Kees,

    Sorry, but it is not my problem!!! :)


  9. chris vo says:


  10. lisa says:

    Thank you for your post! I found it very useful and fast for my website!

  11. Peter Cunningham says:

    Thanks very much, that worked perfectly for me too.

  12. Greg Zeck says:

    You the man! Thanks so much!

  13. Wine Dine says:

    Thanks for image sorting tip!

  14. johnny says:

    didn’t work for me, i have the latest version of both WP and NEXT GEN :(.

    i’m a professional photographer, so my site is very image intensive and a massive pain in the ass with NEXT GEN.

  15. debbie says:

    wonder about sorting the actual gallery order as it appears on my webpage, image sorting inside each gallery works fine. thanks, debbie

  16. Xplode Ads says:

    Thanks Man!
    You are Genius. You have solved my problem.

    Keep updating your blog.


  17. Thanks for the fix. Is there an addon plugin to help me change the dates for the images? All of my images were loaded at the same time so they all have the same date and would love to move the around.

Leave a Reply