With the new Gallery editor in Wordpress I am able to set up my galleries and to drag the Thumbnails to re-arrange the image order. On the backend that seems to work fine. But I ran into an issue when I try to display the gallery on the front end using the 'orderby' => 'menu_order' attribute. The display was not using menu_order. When I looked in the database I noticed that the menu_order value for my attachments was still '0' for all gallery images. So it looks like reordering and saving Galleries in Wordpress 3.5 does not set the menu_order value in the database. Is this a bug? Has anyone else run across this? If so do you know of a fix?
it seems to me, after going through the source codes (both PHP and JS), that gallery and it's order is not saved to database at all. Gallery exists only in JS when you are creating that and even does not persist when you leave a post editing page.
Gallery gets saved only by inserting gallery shortcode with exact order of IDs declared in that shortcode - no extra info is saved to database, it is all about that shortcode.
If you want to loop attachements of a post by menu order, you have to assign to attachment post_type new support for page-attributes from plugin or your functions.php by inserting this code:
But, frankly, to assign menu order by enterin' each attachement edit page is quite pain. If you need to list post's attachement by menu order, WP 3.5's default Gallery is not for you and I suggest you to use some proven plugin (eg. NextGen Gallery) or write down a custom plugin which will enable you to either set menu order from Media Uploader or Library.
You are correct.
The menu_order is no longer used for media in the gallery. Unfortunately, it looks like the only "source" of the gallery order is the "ids" argument for the gallery shortcode which is embedded in the page/post content.
Not sure if this is by design or an oversight, but it could be by design since you can now include media in a gallery even if it is not "attached" to the page/post. In any case, below is the method I use to grab the ids and get the attachments based on the order specified in the shortcode.
The key is that the "orderby" param on the call to get_posts must be "post__in" this tells it to order by the post id order specified in the "include" param. See below.
This isn't ideal and it would be nice if WP core would store this ordering in the database somewhere, but it works until we have a cleaner way.
Hope that helps!
I had a similar issue, it appears the menu order isn't being set until you make a change by dragging an image to a new location, then it is saved asynchronously for all images in the set.
The menu order also seems to be limited only to the images attached to a particular post, although honestly I haven't played with the others as much.
Hope it helps.