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

We have a complicated database query and we would like to exclude some posts. We've tried to do it with SQL, but it's really complicated. The simplest solution seems to loop through the results after the query's made and then exclude a few posts. The problem is, i don't know where to do it! I've tried to unset posts in $wp_query->posts, but they still show up. Is there a proper way to do this? Is there another array WordPress uses that I should unset from?

share|improve this question
Please show your actual code (query) and explain your exact problem. – kaiser May 28 '14 at 13:04

Do you know the ID of the posts? Have you passed post__not_in as part of your query?

$query = new WP_Query( array( 'post_type' => 'post', 'post__not_in' => array( 2, 5, 12, 14, 20 ) ) );

From: http://codex.wordpress.org/Class_Reference/WP_Query. The above will return all posts but exclude the IDs specified.

Or do you have another way to group the posts you do not want i.e. by a category or author? A bit of context might help :)

share|improve this answer
It's a website for renting apartments. We want to only show properties that will be available in the next 3 months. – user52282 May 28 '14 at 13:26
And how are you specifying when it might be available – custom fields? – lotech May 28 '14 at 19:45

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.