
Limit Jetpack’s Related Posts To A Specific Date
Today, I was double-checking an article that I had written and noticed that the related post that came up was from 9 years ago on a platform that no longer existed. So, I decided to take a deeper look at the Jetpack related posts options on my site and see if I could limit the date range.
Jetpack does a fantastic job of selecting the relevant posts that are similar, but unfortunately, it has no idea that many of the articles may be out of date. I often remove old posts that make no sense, but I don’t have time to review all 5,000 articles I’ve written for over a decade!
Unfortunately, there’s no setting on Jetpack to accomplish this, you can only set whether or not you wish to have a headline, what the headline is, and options for the layout, whether to show thumbnails, whether to show the date, or whether to show any content.

As with virtually everything in WordPress, though, there’s a robust API where you can customize your child theme (or theme’s) functions.php file and modify how it works. In this case, I want to limit the scope of any related posts to 2 years… so here’s the code:
function dk_related_posts_limit( $date_range ) {
$date_range = array(
'from' => strtotime( '-2 years' ),
'to' => time(),
);
return $date_range;
}
add_filter( 'jetpack_relatedposts_filter_date_range', 'dk_related_posts_limit' );
This adds a filter to the query that the related posts plugin uses. I uploaded the update to my site and now the related posts are limited to anything written in the last 2 years!
There are additional ways of customizing your related posts as well, check out the Jetpack support page on the topic.
Disclosure: I’m using my WordPress and Jetpack affiliate links in this post.