Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

0 down vote favorite

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

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

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

2 Answers 2

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

 
discard

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.