Custom page title sort


Is it possible to sort pages by page title, but using the second word? I have people pages and would like to sort by surname.


Yes, I think you can use sortBy() with a callable now

$pages->sortBy(function($child) {
  // use part you want to sort by 
  // use string functions here to get the part of the title to sort by
}, 'desc');
1 Like

thanks! this is great. Ended up with this:

$pages->sortBy(function($child) {
 	    $words = explode(' ', $child->title());
        $last_word = array_pop($words);
        return 	$last_word;
}, 'asc');