Tutorial by Examples

Each time WordPress loads the page, it will run main loop. The loop is the way to iterate over all elements related to the page you are currently on. Main loop will work on a global WP_Query object. The query has a globalized method have_posts(), that allows us to loop through all results. Finally...
You can also use loop with curly brackets like this: if ( have_posts() ) { while ( have_posts() ) { the_post(); var_dump( $post ); } }
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;

Page 1 of 1