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.

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
1  
Please show your actual code (query) and explain your exact problem. –  kaiser May 28 at 13:04

1 Answer 1

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 at 13:26
    
And how are you specifying when it might be available – custom fields? –  user1001657 May 28 at 19:45

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.