Filter for each loop when WP_Query has no posts to show

Adding a if (has_posts() ) solved the issue which I forget to add. See the updated code in the question.

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)