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.

I'm currently running this query to get pages (not posts) from the site section:

query_posts("post_type=page&post_parent=6");

I'd like to remove one page, 271, from this query. Based on this stack I tried:

query_posts("p=-271&post_type=page&post_parent=6");

Unfortunately this had the opposite of the intended result, showing only page 271 and not the other pages in the loop. Placing the p=-271 at the end of the query had the same unsuccessful result.

How can I reverse this to show all the other pages except page 271?

share|improve this question

1 Answer 1

up vote 1 down vote accepted

Update:

You must use exclude the page using post__not_in paremeter. Rewrite your query using the array parameters

query_posts(array(
'post__not_in'=>array('271'),
'post_parent'=>6,
'post_type'=>'page'
)
 );

See this page for reference.

share|improve this answer
    
Thanks for the quick reply. Unfortunately when I try that code it throws an error (saying it needs an array). When I try this query_posts(array("post__not_in=271&post_type=page&post_parent=6")); it displays posts instead of pages. Anything else I can try? –  Ryan Mar 4 '11 at 19:51
    
See my edit: the query above retrieve all the childs of the page with ID 6 , excluding the page that has ID 271 –  keatch Mar 4 '11 at 22:10
    
Works perfectly - thank you! –  Ryan Mar 5 '11 at 0:22

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.