Remove Old Posts From Jetpacks Related Posts

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.

Was This Tutorial Helpful?

Free

$0

Access only to all free tutorials per month.



Monthly

$75

Access to 10 premium tutorials per month.


Tutorial Request


Includes code guarantee and coding support.

Yearly

$500

Access to 15 premium tutorials per month.


Monthly Tutorial Request


Includes code guarantee and priority coding support.