WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] sort by a number field with query_posts (4 posts)

  1. ixiter
    Member
    Posted 1 year ago #

    Hi,

    I am trying to sort a query by a custom field. The cf is a single cf and it contains numbers.
    For some reason when i try to sort some posts by that number field, it handles the fields as text fields and the order result is wrong.

    Example:
    I have 3 posts with the following numbers in that field
    23000
    1234560
    250000

    The ASC ordered result is:

    1234560
    23000
    250000

    This is inappropriated to my purpose. I need the correct order by number like:

    23000
    250000
    1234560

    Any idea to fix this? Maybe even quick & dirty.

  2. bythegram
    Member
    Posted 1 year ago #

    'orderby' => 'meta_value_num' should do the trick if I'm not mistaken
    http://codex.wordpress.org/Class_Reference/WP_Query#Order_.26_Orderby_Parameters

  3. ixiter
    Member
    Posted 1 year ago #

    Thank you very much bythegram, for this top answer. I've read that page before but missed that all saying point somehow. OK, was at the end of a hard day .. thats my excuse. :)

  4. bythegram
    Member
    Posted 1 year ago #

    No worries! It happens to the best of us. Cheers!

Topic Closed

This topic has been closed to new replies.

About this Topic