Skip to content

Instantly share code, notes, and snippets.

@jchristopher
Created October 22, 2020 09:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jchristopher/433280821f91dbb826bc7e815d16622e to your computer and use it in GitHub Desktop.
Save jchristopher/433280821f91dbb826bc7e815d16622e to your computer and use it in GitHub Desktop.
Sort SearchWP results in alphabetical order
<?php
// Sort SearchWP results in alphabetical order.
add_filter( 'searchwp\query\mods', function( $mods ) {
$mod = new \SearchWP\Mod( \SearchWP\Utils::get_post_type_source_name( 'post' ) );
$mod->order_by( function( $mod ) {
return $mod->get_local_table_alias() . '.post_title';
}, 'ASC', 1 );
$mods[] = $mod;
return $mods;
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment