Thread Starter
Pete
(@perthmetro)
I’m not sure if this is the best/correct way but it works now…
<?php if ( have_posts() ) : ?>
<?php query_posts($query_string . '&orderby=date&order=asc'); ?>
<?php while ( have_posts() ) : the_post(); ?>
query_posts() is not a very good approach under any circumstance these days, I think it’s mainly left in for reverse compatibility. Much better is to use the pre_get_posts action to alter the appropriate query vars without destroying the others, which is what query_posts() does. The examples illustrate typical setups. In your case, once you’ve determined the current query is the one to alter, you would set the query vars with:
$query->set('orderby', 'date');
$query->set('order', 'asc');
Thread Starter
Pete
(@perthmetro)
Like this?
function order_home_asc($query) {
if ($query->is_home() && $query->is_main_query()) {
$query->set('orderby', 'date');
$query->set('order', 'asc');
}
}
add_action('pre_get_posts', 'order_home_asc');
It sadly seems an awful lot of bother just to arrange a list a of posts by ascending date!
That is how it’s done. It is a lot of bother, it happens sometimes with OOP, the price we pay for modularity and flexibility is formalized routines for tasks, be they simple or complex.
It’s not so apparent, but behind the scenes this is way less bother than calling query_posts(), trust me.
I simply added:
'paged' => ( get_query_var('paged') ? get_query_var('paged') : 1),
to my query_posts args. That worked for me.