I have a CPT called authors. Titles include first and last names. To alphabetically sort these posts by surname I use this filter:

function posts_orderby_lastname ($orderby_statement) 
  $orderby_statement = "RIGHT(post_title, LOCATE(' ', REVERSE(post_title)) - 1) DESC";
    return $orderby_statement;

Now I need to group posts with surnames starting with the same letter under one same heading "A", "B"... "Z". I know how to do this looking at the first letter of the post title, but how to do it with the first letter of the surname in my case?

  • What is the context? Is this the main query? A secondary query? – s_ha_dum Feb 23 '14 at 19:45
  • 1
    Your question is probably a duplicate of this one, in principle: wordpress.stackexchange.com/q/110875/21376 – s_ha_dum Feb 23 '14 at 19:48
  • Wow you're awesome, your solution on this link works perfectly. – drake035 Feb 23 '14 at 22:27
  • Feel free to upvote anytime, anywhere :) – s_ha_dum Feb 23 '14 at 22:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.