Display Year in descending order

I have a Year taxonomy. I imported the list of years with bulkpress and the years were listed in descening order with 2019 as the first entry (top). After I imported and checked in Add Listing, the years in the Year dropdown are listed in asceding order and 2019 is at the bottom of the list. So I deleted all the years and then add, manually, 2019, to the Year taxonomy and then 2018. Then I checked in Add Listing and 2019 was displayed at the top. I then manually entered 10 more years. Then I checked again and 2019 was displayed at the bottom of the list. How can I fix this?

Created: June 22, 2018 at 6:53 pm
  • In: Auction Theme
  • Started by: Roy
  • 4 members left 5 comments
  • Last reply from: JamesDJamesD

  • JamesD
    June 30, 2018 at 1:18 am

    Hello Roy,

    Note: This assumes you’re working with a + theme.

    This would require to alter a core theme file which is discouraged since you could overwrite changes when the theme updates. Always back up any file(s) before editing.

    The default ‘order’ is set as descending already, however ‘orderby’ is going by the count. You’ll need to change the ‘orderby’.

    One way to do this is by changing the ‘orderby’ to ‘name’:
    Open /wp-content/themes/AT/
    Start around line #7093 you should see:

    $terms = get_terms($field['taxonomy'],"orderby=count&order=desc&get=all");
    And replace those lines with:
    $aArgs = array('orderby' => 'count', 'order' => 'DESC', 'get' => 'all');
    if($field['taxonomy'] === 'year'){ $aArgs['orderby'] = 'name'; }
    $terms = get_terms($field['taxonomy'], $aArgs);
    Note: This also assumes your taxonomy name is called ‘year’ and the names are the year. If not, then replace the ‘year’ with the proper taxonomy and instead of ‘name’ change it to the attribute you need ( slug if the ‘slugs’ are the year values).

    Hope that makes sense. 🙂

  • Roy
    July 2, 2018 at 10:27 pm

    Thanks. I realize that altering core files is not a smart thing to do. But if it is altered in a child theme then the original would still be okay, no?

  • Jason
    July 2, 2018 at 11:00 pm

    Couldnt this be done via FUNCTIONS, ?

    Just a thought

  • Mark Fail
    Mark Fail
    July 2, 2018 at 11:39 pm

    @Roy,editing via a child theme is the best option yes.

  • JamesD
    July 2, 2018 at 11:45 pm

    Yes, one could, but it would be a bit more involved.

    There are usually multiple ways of handling things like this. I just went for the first thing that came to mind that would be the easiest and most direct way without getting too involved.

    Using javascript would probably be the next easiest. I’m not aware of any hooks that would offer an easy/quicker alternative to handle it.

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