I am using Wordpress gallery in a theme.

I am trying to change the order of images by changing the order of ids but it is not working for me. I have searched relative questions to wordpress gallery but nothing is working for me.

I also have deactive all the plugins. I also do not have install any post type order plugin in my theme.

The short code for the galleries are

 [gallery columns="4" ids="310,309,311,312,315,314,313"]

[gallery columns="4" ids="309,310,311,312,315,314,313"]

But the result is same for both the short code. here

Please suggest me how to sort the images by ids.


Add order and/or orderby parameters to your shortcode. For example:

[gallery columns="4" ids="310,309,311,312,315,314,313" order="DESC" orderby="ID"]


  • Sorry to say but its not working for me. I have already tried it. I think there is some code in my theme which is forcefully ordering the post. Can you tell me what could be that code so that I can search that in my theme. – Vijay Lal May 15 '15 at 4:49
  • ok I found the code. It was a hook of add_filter to 'posts_orderby' and function was using global $wpdb. I removed it and now working for me. – Vijay Lal May 15 '15 at 5:59
  • How could I have possibly told you what code in your theme, which you haven't named and which is one of hundreds or thousands of themes, was causing the problem? – s_ha_dum May 15 '15 at 13:29
  • Agreed, I have solved the problem. I asked because i also was not aware what would be the code, I hoped an expert will have knowledge about what code can cause the problem. – Vijay Lal May 15 '15 at 13:50
  • 1
    There are probably a dozen ways to break a gallery. That is the problem with guessing without seeing the code. – s_ha_dum May 15 '15 at 13:51

I had a similar problem where the images did not display in the correct order in admin but did display in the correct order on the front end. After many many, many hours of research and pulling my hair out! I stumbled on this post. I then hunted through a very customized function file where I found a filter that captured all ajax calls and ordered by ID! As soon as I removed this filter the gallery displayed in the correct order!

For those who are interested the filter was add_filter('ajax_query_attachments_args', ' ----------- ');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.