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

I have created a custom WP_Query as seen below. The query works well except for when $favorites is empty. When $favorites is empty, the query still outputs posts, which I don´t want. It could seem like it defaults back to the standard WP_Query to output all published posts.

Anyone knows what´s going on?

$favorites = wpfp_get_users_favorites($user = '');
$favorites_query = new WP_Query(array('post__in' => $favorites));

while ($favorites_query->have_posts() ) : $favorites_query->the_post();


share|improve this question
up vote 2 down vote accepted

Empty argument here does not equal logical in nothing. It equals no value to process and so WP ignores it and goes further as usual.

Just wrap your query in if( !empty( $favorites) ) condition.

share|improve this answer
Awesome. Thanks man! – Espen Arnoy Oct 6 '10 at 16:13

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.