-
-
Save searchwpgists/015e331b08a0e2c320495bd9ff0050f2 to your computer and use it in GitHub Desktop.
Add secondary sort to SearchWP results to sort matching relevance results by Title in ASC order
This file contains 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
<?php | |
// Add secondary sort to SearchWP results to sort matching | |
// relevance results by Title in ASC order. | |
add_filter( 'searchwp\query\mods', function( $mods, $query ) { | |
global $wpdb; | |
$mod = new \SearchWP\Mod(); | |
$mod->set_local_table( $wpdb->posts ); | |
$mod->on( 'ID', [ 'column' => 'id' ] ); | |
$mod->order_by( function( $mod ) { | |
return $mod->get_local_table_alias() . '.post_title'; | |
}, 'ASC', 99 ); | |
$mods[] = $mod; | |
return $mods; | |
}, 30, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment