WordPress 3.5 Gallery Menu Order not set?

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?

4 Answers
4

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:

add_action('init', 'my_custom_init');

function my_custom_init() {
    add_post_type_support( 'attachment', 'page-attributes' );
}

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.

Leave a Comment