Display posts with date wordpress default

I’m trying to display last posts with WordPress date, not date from server.

<?php 
$week = date( 'W' );
$year = date( 'Y' );
$query = new WP_Query( 'year=' . $year . '&w=' . $week );

while ( $query->have_posts() ) { $query->the_post();

    // Page title
    the_title(); 


} // end while

// Restore original Post Data
wp_reset_postdata();

// Save memory
unset( $query );

;?>

what is wrong?
How i can use to show last x day posts with date wordpress default?

Solutions Collecting From Web of "Display posts with date wordpress default"

you need to study about date query.
Anyways following should work

<?php 
$args = array(
  'posts_per_page' => -1,  
  'date_query' => array(
     array(
           'after' => '7 days ago'
           )
     )
  );

$query = new WP_Query($args);

while ( $query->have_posts() ) { $query->the_post();

    // Page title
    the_title(); 


} // end while

// Restore original Post Data
wp_reset_postdata();

// Save memory
unset( $query );

;
?>