Grow your CSS skills. Land your dream job.

WordPress Sort Array Numerically

  • # June 12, 2012 at 5:12 am

    Hi Guys,

    If anyone can help me I would LOVE to hear it. I have a frustrated client and I am pulling my hair out and have been for days.

    We’ve set up drop down lists to allow people to filter posts based on custom post types.

    In order to populate the drop down list I am using:



    It outputs a long list of Ratio;s eg 1.67, 2.42, 10, 13.23 etc etc

    Listing these alphabetically doesn’t work, as it outputs 1.67, 10, 2.42 etc

    The slug and the name are pretty similar, so I don’t mind which one we are using.

    So I need to list them as integers… Any help would be really appreciated, whether its a php solutions, jQuery, wordpress… I don’t care… I just need to make it happen.

    The site is here if you need more of an idea: http://amigaeng.com.au/gearbox-list/

    Thanks so much!

    Matt

    # June 12, 2012 at 10:44 am

    Solved it with jQuery… I am definitely a jQuery hack and there are still a few strange issues going on… but its a lot better:


    $("#ratio").html($("#ratio option").sort(function (a, b) {
    var aValue = parseInt(a.value);
    var bValue = parseInt(b.value);
    return aValue == bValue ? 0 : aValue < bValue ? -1 : 1;
    }));
Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".