• Hi there,

    I’m using wordpress for book reviews and every category stands for one particular author like “Hermann Melville”. Now I’m facing the following problem:

    I’d like to order all posts by author, but since the categories are “First Last”, they are also sorted the first name and I can’t need that. I need them to be sorted by last names.

    Does anyone have an idea how to achieve that, or does anyone have a smart solution for that sorting issue?

    Thanks a lot in advance.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Hello wutzelmutz, it could be relatively easy to order categories by slug if the slug have “last-first” type.
    You didn’t mention where and how you want to display a list. How do you order posts by authors now?

    Thread Starter wutzelmutz

    (@wutzelmutz)

    I’m actually using the lists on a custom archives page where I sort my posts by title (“book title” by author) and by author (“author”: “book title”).

    What about middle names and authors with more than two first or last names, does the slug work with that too?

    Ok, now I get that you want to order posts by authors, not categories. You can use custom post meta feature for sorting posts. For example, you can add custom meta key “book_author” to each post with values “Melville Hermann”, “Tolstoy Lev Nikolaevich”.
    Then you can use WP_Query with orderby parameter by meta_value
    $query = new WP_Query( array ( 'orderby' => 'meta_value', 'meta_key' => 'book_author', 'order' => 'ASC' ) );
    It will show posts with “book_author” meta and sort by meta values in alphabetical order.
    Of course, there are more details with implementing WP_Query, like pagination and wp_reset_query().

    In fact, the task of organising this kind of site could be more complex. Perhaps you have to read about custom taxonomies WP feature.

    Thread Starter wutzelmutz

    (@wutzelmutz)

    vjpo, reads like that’s exactly what I was looking for. I will defo try that out. Thanks a lot!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Categories as book authors’ is closed to new replies.