Simple WordPress Filter Query and Sorting

Posted by: Alex on July 4, 2013

This Code Byte provides a very simple & cheeky/lazy way of creating filters to query certain post types/fields and sort them.

Within WordPress admin you can of course filter your content by clicking on a field like so:
wordpress-filter-queries

You will then notice your url changes to:
wp-admin/edit.php?orderby=title&order=asc

Although this is a PHP GET request, it’s actually usable within your theme to set up specific queries, like sorting by a certain field, or post/page type.

This example will query posts and sort them by their Title in Ascending order:

<?php query_posts( 'orderby=title&order=asc' ); ?>

Of course, this is very simple, but sometimes a little easier than trying to remember or find out the field name you want to sort by.