Support » Fixing WordPress » How can I order my posts using multiple meta values?
5 years, 1 month ago
I run a book reviews blog and would like to make a list of my posts and have them ordered alphabetically using two meta values (different meta keys) – first by book_author then book_title.
My current query only orders the posts alphabetically by book_author:
$args = array(
'posts_per_page' => 100,
'category_name' => 'Upcoming Reviews',
'meta_key' => 'book_author',
'orderby' => 'meta_value',
'order' => 'ASC',
$upcomingReviews = new WP_Query( $args );
Which means books with the same author are ordered by date posted. For eg.
Author | Title
Austen, Jane | “Pride and Prejudice”
Tolkien, J. R. R. | “The Hobbit”
Tolkien, J. R. R. | “The Children of Hurin”
I want a query that will also list the titles alphabetically, so in the example above, “The Children of Hurin” should be listed above “The Hobbit”.
My list is here if it makes my question clearer: http://bookishnature.com/reviews/
Any help would be great appreciated.
Thank you in advance.
Try it with: 'orderby' => 'meta_value title',
'orderby' => 'meta_value title',
You. Are. Amazing!
Worked like a charm 🙂
I have been looking for a solution for the last few days and it’s been killing me, so thank you!
4 years, 9 months ago
Yes, WordPress is Woaaaaaaaaaaaaaaaa Amazing!!!!
(Made my day)