Skip to content

Instantly share code, notes, and snippets.

@BrElio
Forked from jchristopher/searchwp-customizations.php
Last active December 10, 2020 11:15
Show Gist options
  • Select an option

  • Save BrElio/df70e0b00a2aa89df22c3c7b6d4ff197 to your computer and use it in GitHub Desktop.

Select an option

Save BrElio/df70e0b00a2aa89df22c3c7b6d4ff197 to your computer and use it in GitHub Desktop.
Add extra weight to specific post types
<?php
//Add extra weight to specific post types
add_filter( 'searchwp\query\mods', function( $mods ) {
$source_extra_weight = [
\SearchWP\Utils::get_post_type_source_name( 'post') => 100000,
\SearchWP\Utils::get_post_type_source_name( 'page') => 1000,
];
$mod = new \SearchWP\Mod();
foreach( $source_extra_weight as $source => $extra_weight ){
$mod->weight( "IF({$mod->get_local_table()}.source = '{$source}', {$extra_weight}, 0)" );
}
$mods[] = $mod;
return $mods;
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment