Yes. There’s an option for that in Relevanssi Premium, or you can do it with some code. See “Date-based weight” here: https://www.relevanssi.com/knowledge-base/relevanssi-match/
Hm…. tha’ts not exacty what I’m looking for. It gives a boost for pages newer than 1 week.
What I want is a dynamic date weight. Sure I can set many many if..
< 1 day
< 2 days
< 3 days
< 4 days
…
< 365 days
…
But this is not a nice practical solution with much code (affects load time)
Any ideea how to get it done somehow else?
That’s still the method you’d need to use. Instead of the fixed date modifier, you can use a function that converts the date to a weight multiplier.
Perhaps count the age of the post in days, then subtract that from a suitable number? Something like that, so that a fresh post gets a multiplier of 365 and anything at least a year old gets a multiplier of 1.
There are many approaches to this, but no matter how you do it, you’d still need to write the relevanssi_match filter hook that adjusts the weight based on the age of the post.
I’m a marketing guy, not a programmer… sounds like this is a bit to tricky for me!?
Well, you can always hire a programmer… but here’s a more dynamic time-based weight system for you, add this to your theme functions.php file:
add_filter( 'relevanssi_match', 'rlv_dynamic_time_weights' );
function rlv_dynamic_time_weights( $match ) {
$now = date_create( 'now' );
$post_date = date_create( get_the_time( 'Y-m-d', $match->doc ) );
$diff_days = $now->diff( $post_date, true )->format( '%a' );
if ( $diff_days < 1 ) {
$diff_days = 1;
}
$date_weight_multiplier = 500 / $diff_days;
$match->weight = $match->weight * $date_weight_multiplier;
return $match;
}