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?


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.

| improve this answer | |

Change your Query to

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

This is the right parameter.

| improve this answer | |
  • 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 clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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