Skip to content

Instantly share code, notes, and snippets.

@cassler
Created July 14, 2014 16:32
Show Gist options
  • Select an option

  • Save cassler/86c6bb459a1d360ac58a to your computer and use it in GitHub Desktop.

Select an option

Save cassler/86c6bb459a1d360ac58a to your computer and use it in GitHub Desktop.
Filter by Last Name
/**
* Filters posts by last word in title
*
* Particularly useful for sorting staff lists by last name alphabetically
**/
function posts_orderby_lastname ($orderby_statement) {
$orderby_statement = "RIGHT(post_title, LOCATE(' ', REVERSE(post_title)) - 1) ASC";
return $orderby_statement;
}
// Your Loop
remove_filter( 'posts_orderby' , 'posts_orderby_lastname' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment