I currently use the following code to list posts in Archive.php but I want the results to be ordered by name in ascending order, I have checked the codex but the answer isn’t clear to me, how can I get this working?
<?php $post = $posts[0]; // ?>
Thanks in advance.
The easiest way to do this is to use a hook (the
pre_get_posts
hook) to change the order. But you should check that the query is one for which you do want to alter the order! (is_archive()
oris_post_type_archive()
should be sufficient.)For instance, put the following in your theme’s functions.php…
further to Stephen’s answer, if you want to just query and order by the title, you could use this in your template file: