tags:

views:

21

answers:

2

I am ordering my posts by using a custom field "order".

For each post the value of order is a number, which dictates where I want the post to be positioned.

I have the following:

query_posts('category_name=category&meta_key=order&orderby=meta_value&order=ASC');

This seems to have worked fine up until post #10, this posts positions itself at 2nd in the list.

Any ideas as to where I am going wrong?

A: 

Ok, found the answer elsewhere.

Because the custom field value is alphabetic and not numeric. You have to begin your ordering with 01, 02, 03...10, 11

and not 1, 2, 3...10, 11

Oldie
A: 

Another option is to create a custom query string that casts your alphabetic custom field as a decimal in the ORDER BY clause:

$querystr = "
    SELECT wposts.*
    FROM $wpdb->posts wposts, $wpdb->postmeta wpostmeta
    WHERE wposts.ID = wpostmeta.post_id
    AND wpostmeta.meta_key = 'your-custom-field-name' 
    AND wposts.post_type = 'post'
    ORDER BY CAST(wpostmeta.meta_value AS DECIMAL) DESC
";
Pat
That is also a good solution. Thanks.
Oldie