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!
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.