[resolved] How can I order my posts using multiple meta values? (5 posts)

  1. Winifred
    Posted 4 years 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.

  2. keesiemeijer
    Posted 4 years ago #

    Try it with: 'orderby' => 'meta_value title',

  3. Winifred
    Posted 4 years ago #

    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. gleenk
    Posted 4 years ago #

    Woaaaaaaaaaaaaaaaa Amazing!!!!

  5. keesiemeijer
    Posted 4 years ago #

    Yes, WordPress is Woaaaaaaaaaaaaaaaa Amazing!!!!
    (Made my day)

Topic Closed

This topic has been closed to new replies.

About this Topic