Change the order of posts in an archive page

WordPress displays posts according to publish date, newer comes first. It happens in all archive pages, even in home page.

Did you ever need of changing order of posts in archive page? Or you thought? Well, there is an easy code snippet to shows posts in reverse order. You can add this codes in your functions.php in the theme, if you think your theme won’t be changed. Otherwise mu-plugins is the best solution.

function change_order($orderby, $query) {
global $wpdb;
$orderby = “{$wpdb->prefix}posts.post_date ASC”;
return $orderby;

Here is_archive() is used to check if the page is only an archive. If you want for all pages, just remove that conditions.

You may also read:  Easily display member cards with WPMU DEV Membership

Also if you need in home page, tag archive page or even in search results page you can use the relevant conditions like:


You may also like...

Leave a Reply

%d bloggers like this: