Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End WordPress Sort Array Numerically

  • This topic is empty.
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #38481
    mtedwards
    Member

    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

    #104282
    mtedwards
    Member

    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)
  • The forum ‘Back End’ is closed to new topics and replies.