0

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?

1
  • 1
    Please show your actual code (query) and explain your exact problem.
    – kaiser
    May 28, 2014 at 13:04

1 Answer 1

0

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 :)

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

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.