Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- add_filter( 'posts_orderby', function( $orderby, WP_Query $q )
- {
- if( 'wpse_last_word' === $q->get( 'orderby' ) && $get_order = $q->get( 'order' ) )
- {
- if( in_array( strtoupper( $get_order ), ['ASC', 'DESC'] ) )
- {
- global $wpdb;
- $orderby = " SUBSTRING_INDEX( {$wpdb->posts}.post_title, ' ', -1 ) " . $get_order;
- }
- }
- return $orderby;
- }, PHP_INT_MAX, 2 );
- add_filter( 'posts_orderby' , 'posts_orderby_lastname' );
Add Comment
Please, Sign In to add comment