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.

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();

Thanks!

share|improve this question
add comment

1 Answer

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
add comment

Your Answer

 
discard

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