exclude a post from wp_query loop wordpress

I show my last post in a page with this code:

$query1 = new WP_Query();
$query1->the_post();

and it further with:

Read More
$id = $query->ID;

to retrive last post ID
so I wrote a new wp_query and I want to exclue that ID from the results:
I wrote this but it don’t work:

$query2-> new WP_Query('p=-$id');

what’s the problem?

Related posts

Leave a Reply

2 comments

  1. My code is works fine:

    $ID =array('1,2,3,4,5');
    $news = new WP_Query(array('
        'post_type'    => 'post',
        'showposts'    =>3,
        'order'        => 'DESC',
        'post__not_in' => $ID
    ));
    if ( $news->have_posts() ) :
        echo '<div>';
            while ( $news->have_posts() ) : $news->the_post(); ?>`
    
                //Your code here