WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

0 down vote favorite

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

$query1 = new WP_Query();

and it further with:

$id = $query->ID;

to retrieve 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?

share|improve this question
up vote 1 down vote accepted

If I'm understanding your specific question (and posted code) correctly, you're actually trying to exclude the most recent post from your query? If so, there's a much easier method: use the offset parameter:

$query2 = new WP_Query( array( 'offset' => 1 ) );

Using this method, you exclude the most recent post from $query2, and never actually need to run $query1.

share|improve this answer

Change your Query to

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

This is the right parameter.

share|improve this answer
Thank you but what is (P)? – Ehsan Feb 7 '13 at 14:25
If you just want to exclude a Post, do the above. p is if you want to specifically target one post. – fischi Feb 7 '13 at 14:50

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.