Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Add secondary sort to SearchWP results to sort matching relevance results by Title in ASC order
<?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