RSS feed for the previous week’s posts

If this is possible, how to get a RSS feed for the previous week’s posts?

I found a sollution from @Bainternet (see 1, 2), but I don’t understand how to implement it in my case.

Right now I can display posts from the previous week (see the bellow code, adapted a little from the wpbeginner.com), but I need a feed link also.

// Display previous week’s posts
add_shortcode('lastweek', 'wpb_last_week_posts');

function wpb_last_week_posts() {
  ob_start();
    $thisweek = date('W');
    if ($thisweek != 1) :
        $lastweek = $thisweek - 1;   
    else : 
        $lastweek = 52;
    endif; 
    $year = date('Y');
    if ($lastweek != 52) :
        $year = date('Y');
    else: 
        $year = date('Y') -1; 
    endif;
    $the_query = new WP_Query( 'year=' . $year . '&w=' . $lastweek .  'posts_per_page=5' );
    if ( $the_query->have_posts() ) : 
        while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
            <h2><a href="<?php the_permalink(); ?>" title="Permanent link to <?php the_title(); ?> "><?php the_title(); ?></a></h2>
            <?php the_excerpt(); ?>
        <?php endwhile; ?>
        <?php wp_reset_postdata(); ?>
    <?php else:  ?>
        <!-- Display recent posts if no posts in the previous week -->
        <ul><?php $the_query = new WP_Query( 'posts_per_page=5' ); ?>
            <?php while ($the_query -> have_posts()) : $the_query -> the_post(); ?>
            <li><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></li>
                <?php the_excerpt(); ?>
            <?php endwhile;
                wp_reset_postdata();
            ?>
        </ul>

    <?php endif;
  $output = ob_get_contents();
  ob_end_clean();
  return $output;
}

Solutions Collecting From Web of "RSS feed for the previous week’s posts"

You could try to modify the feed query directly via:

/**
 * Modify the main feed query to show posts from the previous week, 
 * when the GET parameter wpse_previous_week is set
 *
 * @link http://wordpress.stackexchange.com/a/194843/26350
 */
add_action( 'pre_get_posts', function( $q )
{
    if(    $q->is_feed() 
        && filter_input( INPUT_GET, 'wpse_previous_week', FILTER_SANITIZE_NUMBER_INT ) 
    )
        $q->set( 'date_query', 
            [
                [ 
                    'before'    => 'Sunday previous week', 
                    'after'     => 'Monday previous week',
                    'inclusive' => true 
                ]
            ] 
        );
} ); 

and view the feed with:

example.tld/feed/?wpse_previous_week=1

Note that you might have to test and modify the date strings to better suit your needs.