Forked from jchristopher/searchwp-customizations.php
Last active
December 10, 2020 11:15
-
-
Save BrElio/df70e0b00a2aa89df22c3c7b6d4ff197 to your computer and use it in GitHub Desktop.
Add extra weight to specific post types
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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