Skip to content

Instantly share code, notes, and snippets.

@searchwpgists
Last active March 9, 2022 15:49
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 searchwpgists/b5bf2c57155fc73bf4a9ba25f6239c9c to your computer and use it in GitHub Desktop.
Save searchwpgists/b5bf2c57155fc73bf4a9ba25f6239c9c to your computer and use it in GitHub Desktop.
Add relevance weight to a single SearchWP Source (Posts)
<?php
// @link https://searchwp.com/documentation/knowledge-base/comparing-index-source-mods/
// Add relevance weight to a single SearchWP Source (Posts).
add_filter( 'searchwp\query\mods', function( $mods ) {
global $wpdb;
$mod = new \SearchWP\Mod();
$source = \SearchWP\Utils::get_post_type_source_name( 'post' );
$mod->weight( $wpdb->prepare( "IF(s.source = %s, 9999999, 0)", $source ) );
$mods[] = $mod;
return $mods;
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment