WordPress.org

Ready to get started?Download WordPress

Forums

the_category sort by ID (5 posts)

  1. nocturnea
    Member
    Posted 6 years ago #

    currently, the_category sorts the categories of a single post alphabetically. i actually need it to sort by ID number, like I think it used to in the beginning.

    Anyway to do this?

  2. MichaelH
    Member
    Posted 6 years ago #

    That's funny, because when it used to sort by ID, the Category Sort plugin was created to sort by category name.

    Didn't test this but wonder if you changed line 80 in
    wp-includes/category-template.php (v2.3.1)

    from
    usort($categories, '_usort_terms_by_name');

    to
    usort($categories, '_usort_terms_by_ID');

    Of course any other uses of get_the_category would also be in that order.

    Make sure you make a copy of that file before trying this.

  3. nocturnea
    Member
    Posted 6 years ago #

    worked like a charm. thanks!

  4. bbx
    Member
    Posted 6 years ago #

    Just wanted to thank you for that. I've been trying to mess with the categories order but it was sorted alphabetically, indeed.

    By the way, is there a way to invert the order? I mean, it would still sort by ID but like 3,2,1 and not 1,2,3 ?

    If not, it's not a big deal.

  5. Exper
    Member
    Posted 6 years ago #

    Thanks a lot MichaelH.
    It works prefectly also in 2.5.1 and it saved me a lot of headhaces!

Topic Closed

This topic has been closed to new replies.

About this Topic