Ask the community

This is a community support forum where you can ask
questions and interact with other PremiumPress Customers.

Order Results By – Sorting error

  • Michael
    Michael
    Senior Member 141 points
    August 1, 2013 at 12:17 am

    Hello,
    I am trying to sort listings by average score (using WP-PostRating plugin and sorting feature from General Setup panel).
    The score range is 0 to 10.
    For some reason the sorting doesn’t recognize double digits and sees the score “10” as “1”. So the scores go like that : 9, 7.5, 6.2, 4.5, 10, 0.5, 0.

    Does anyone know how to fix this error ?

    Thanks.

  • Mark Fail
    Mark Fail
    Super Guru 12,821 points
    August 1, 2013 at 12:35 am

    iv seen this before with WordPress, it doesnt seem to like 10 (it assumes 1) have you tried 10.1?

  • Richard Bonk
    Richard Bonk
    Super Guru 2,739 points
    August 1, 2013 at 1:04 am

    this is happening if you are sorting custom fields using orderby=meta_value instead of orderby=meta_value_num as it is otherwise ordering numbers as alphabet (and in that case 1 and 10 would follow each other).
    orderby=meta_value – ordering by alphabet
    orderby=meta_value_num – numeric ordering

    Here is the explanation from WordPress Codex:

    ‘meta_value’ – Note that a ‘meta_key=keyname’ must also be present in the query. Note also that the sorting will be alphabetical which is fine for strings (i.e. words), but can be unexpected for numbers (e.g. 1, 3, 34, 4, 56, 6, etc, rather than 1, 3, 4, 6, 34, 56 as you might naturally expect). Use ‘meta_value_num’ instead for numeric values.
    ‘meta_value_num’ – Order by numeric meta value (available with Version 2.8). Also note that a ‘meta_key=keyname’ must also be present in the query. This value allows for numerical sorting as noted above in ‘meta_value’.

    Kind regards,

    Richard
    _____________________________________________________________________
    Wide range of PremiumPress and WordPress Plugins and add-ons
    PremiumPress customisation services and Website Design
    Selection of PremiumPress Child Themes

  • Michael
    Michael
    Senior Member 141 points
    August 1, 2013 at 3:18 am

    I tried to put into the extra field a few variations:
    &orderby=meta_value_number&meta_key=keyname
    &orderby=meta_value_num&meta_key=keyname
    &meta_value_num=yes&meta_key=keyname

    None of them seem to work :(

  • Richard Bonk
    Richard Bonk
    Super Guru 2,739 points
    August 1, 2013 at 9:58 am

    I don’t think you can change the ‘orderby’ as it is hardcoded in the class_design.php.
    I think Mark should add a new tick box to select whether the field is numeric or not and modify the orderby accordingly.

  • Michael
    Michael
    Senior Member 141 points
    August 1, 2013 at 3:49 pm

    I don’t think you can change the ‘orderby’ as it is hardcoded in the class_design.php.
    I think Mark should add a new tick box to select whether the field is numeric or not and modify the orderby accordingly.

    So Mark, can this issue be fixed?

Viewing 6 posts - 1 through 6 (of 6 total)