Last active
March 9, 2017 14:27
-
-
Save jchristopher/179e51bef82af7fcc77cc90322d09801 to your computer and use it in GitHub Desktop.
This file contains 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 search weight to more recently published entries | |
*/ | |
function my_searchwp_add_weight_to_newer_posts( $sql ) { | |
global $wpdb; | |
// Adjust how much weight is given to newer publish dates. There | |
// is no science here as it correlates with the other weights | |
// in your engine configuration, and the content of your site. | |
// Experiment until results are returned as you want them to be. | |
$modifier = 15; | |
$sql .= " + ( 100 * EXP( ( 1 - ABS( ( UNIX_TIMESTAMP( {$wpdb->prefix}posts.post_date ) - UNIX_TIMESTAMP( NOW() ) ) / 86400 ) ) / 1 ) * {$modifier} )"; | |
return $sql; | |
} | |
add_filter( 'searchwp_weight_mods', 'my_searchwp_add_weight_to_newer_posts' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment