Skip to content

Instantly share code, notes, and snippets.

@searchwpgists
Created February 8, 2022 14:38
Show Gist options
  • Save searchwpgists/8dac140387df21375481de34c0002fd2 to your computer and use it in GitHub Desktop.
Save searchwpgists/8dac140387df21375481de34c0002fd2 to your computer and use it in GitHub Desktop.
Give Products extraordinary weight boost to ensure Products show up first.
<?php
// Give Products extraordinary weight boost to ensure Products show up first.
// @link https://searchwp.com/documentation/knowledge-base/post-type-first-top/
add_filter( 'searchwp\query\mods', function( $mods ) {
$post_type = 'product'; // Post type name.
$source = \SearchWP\Utils::get_post_type_source_name( $post_type );
$mod = new \SearchWP\Mod( $source );
$mod->relevance( function( $runtime ) use ( $source ) {
global $wpdb;
return $wpdb->prepare(
"IF( {$runtime->get_foreign_alias()}.source = %s, '999999999999', '0' )",
$source
);
} );
$mods[] = $mod;
return $mods;
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment