Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

When I try to sort a Gallery created through the [gallery] 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 [gallery] 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.

share|improve this question
    
Can you post some code? –  jfacemyer Mar 6 '13 at 16:04
    
There is not much code to post, besides [gallery link="file" columns="6" orderby="title"] which gives the alphabetical order and [gallery link="file" columns="6" orderby="meta_value_num"] which, as stated, doesn't do anything. –  Sunyatasattva Mar 6 '13 at 16:26
add comment

1 Answer

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.

share|improve this answer
    
I know the codex doesn't, but doing some reasearch in the source code made me think it should be possible (considering that it uses get_posts()). –  Sunyatasattva Mar 8 '13 at 16:28
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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