WordPress The Loop (main WordPress loop) Handling no items in the loop


Example

If you want to handle such scenario just add an if/else statement.

if ( have_posts() ) : while ( have_posts() ) : 

    the_post(); 
    var_dump( $post );

endwhile; else :

    __('This Query does not have any results');    

endif;