Created
July 14, 2014 16:32
-
-
Save cassler/86c6bb459a1d360ac58a to your computer and use it in GitHub Desktop.
Filter by Last Name
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * 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