When I try to sort a Gallery created through the shortcode by numerical titles I get them sorted in alphabetical order. That means that they are sorted like so:
1, 3, 34, 4, 56, 6, etc.
rather than so:
1, 3, 4, 6, 34, 56, etc.
Doing some research I came across the section of the codex (in WP_Query
) explaining this issue. Apparently, setting the orderby
parameter to meta_value_num
would enable numerical sorting.
Since internally uses
get_posts()
(wp-includes/media.php::714
), which in turn uses WP_Query
, I thought the same rules would apply.
Changing the order_by
attribute in the shortcode to meta_value_num
doesn’t do the trick. I guess that most likely this is the case because I cannot set up the required meta_key=keyname
.
But not only can I not specify the meta key, I don’t have one, and I don’t need one because I mean to sort them numerically by title.
It doesn’t look like you can do this with the gallery shortcode, unfortunately.
The Codex doesn’t even list
meta_value_num
as an option (though that doesn’t mean it couldn’t work.) However, you’re correct, you must specify a meta-key to use that ordering scheme with WP_Query.