I have a custom taxonomy template, the items are being displayed in the default order, from newest to oldest post.

How would I change the custom taxonomy template to list the posts in the opposite order? Is there a function for this?

1 Answer
1

You can do this with the pre_get_posts action. pre_get_posts fires after the query variable object is created, but before the actual query is run. So you won’t suffer performance penalties by running multiple unnecessary queries.

In your functions.php:

add_action('pre_get_posts','xx_taxnomy_query');
function xx_taxnomy_query($query) {
    if ($query->is_main_query() && ! is_admin() && $query->is_tax('your_taxonomy')) {
        $query->set('order', 'asc');
        return;
    }
}

Leave a Reply

Your email address will not be published. Required fields are marked *