0

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?

1 Answer 1

1

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.

2
  • 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, 2011 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, 2011 at 22:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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