tl;dr;
This is not possible with tax_query
.
A tax_query
is a restriction of the results delivered, not used to order posts. You use the Order & Orderby Parameters for that.
A little excursion into statistics
This has to do with statistics and mathematics, as a taxonomy is a nominal scale, meaning it is just a classification, where every item is on the same level. Like the color of an eye – you can’t say which is better just with this data.
To order data you have to have some kind of a comparison between the data. This is called the ordinal scale, (yeah, the word order is in ordinal), for example 3 is bigger than 2 is bigger than 1, therefor you can order them with the smallest or the biggest first (ASC
and DESC
). Please note that title
also follows an ordinal scale, but not by comparison of the content, but by the scale of the alphabet.
*to be complete, there are also the interval scale and the ratio scale, but those have nothing to do with the WordPress Query.
Back to WordPress
Now as we learned that you can not order a taxonomy (without Metadata), you can just use it to define a group of characteristics the result should have.
In the tax_query
you define a set of characteristics a post should have, nothing more. Please not that a set could also be a restriction like NOT IN
.
After you defined the restrictions with tax_query
(and, to be fair, meta_query
does the same thing with different data), you can tell WordPress how to order your results, based on a measurable variable (be it an integer, alphabetical or any other ordinal scale).
This happens by adding
'order' => 'ASC', // Order Ascending
'orderby' => 'title', // Order by Title
to your $args
array.
a possible solution
One thing you could do, however, is querying your restrictions in sequence, not all together.
Please note that this approach is heavier for the database.
In my example I use an array to define the order of my taxonomies, and loop through this array, querying every taxonomy on it’s own.
By putting the taxonomies into an ordered array, I added a ordinal capability to it. The taxonomy itself is still nominal.
$taxonomies = array(
'editor-in-chief',
'managing-editor',
'fiction-editor',
'poetry-editor',
'nonfiction-editor',
'production-manager'
);
foreach( $taxonomies as $thistaxonomy ) {
$args = array(
'post_type' => 'staff',
'posts_per_page' => '-1',
'tax_query' => array(
array(
'taxonomy' => 'staff-title',
'field' => 'slug',
'terms' => array(
$thistaxonomy
)
)
)
);
/* All your query and magic down there */
}
Hope this works for you!