WordPress.org

Support

Support » How-To and Troubleshooting » [Resolved] How can I order my posts using multiple meta values?

[Resolved] How can I order my posts using multiple meta values?

  • 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:

    <?php
    $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.

Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘[Resolved] How can I order my posts using multiple meta values?’ is closed to new replies.