If you have the Jetpack plugin installed and want to display related posts, you can customize the default functions using code in your child theme.
This code enables you to display posts from within any time frame meaning you can exclude posts older than a specific date from showing in your related posts.
function past_years_related_posts( $date_range, $post_id ) {
$date_range = array(
'from' => strtotime( '-1 year' ),
'to' => time(),
);
return $date_range;
}
add_filter( 'jetpack_relatedposts_filter_date_range', 'past_years_related_posts' );
Uses strtotime
Here’s more code snippets for customizing Jetpacks related posts.
Leave a Reply