I’m trying to use a image as a conditional to show different post types. I have one post with images and another one without images. So I built a If else statement and a while loop that calls the post. At the end I have a page number code. But the loop is infinite, I’m not finding where to close it. Some one can help me?

<?php if (have_posts()): while (have_posts()) : the_post(); ?>
    <div class="texto-longo">
      <?php the_content(); ?>
  <?php endwhile; wp_reset_query(); endif; ?>

  <div class="row-2 w-row">
    $paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
    $args = array(
      'posts_per_page' => 3,
      'paged'          => $paged,
      'cat'            => '3',

    $wp_query = new WP_Query( $args ); 
    <?php if ( $wp_query->have_posts() ) : ?>
      <?php while ($wp_query->have_posts()) : $wp_query->the_post(); ?>

        <div class="_w-image container-novidades">
            <?php if( get_field('imagem_do_evento') ): ?>
      <div class="w-row">
        <div class="column w-col w-col-4"><img class="<?php the_field('imagem_do_evento');?>">
        <div class="colomn-text-novidades w-col w-col-8">
          <h1 class="txt-blue"><?php the_title();?></h1>
          <h3 class="txt-blue"><?php the_field('imagem_do_evento');?></h3>
          <p><?php get_the_date('d/m/Y'); ?></p>
          <p><?php the_field('imagem_do_evento');?></p>


     <?php wp_reset_query(); else : ?>

     <p>Ainda não temos novidades :(</p>

   <?php endif; ?>
<?php endwhile; ?>

      <?php if ($wp_query->max_num_pages > 1) { // check if the max number of pages is greater than 1  ?>
        <nav class="navegacao-paginas">
         <div class="paginacao twisted w-inline-block">
            <div class="seta-text"><?php echo get_previous_posts_link( '⟶' ); // display newer posts link ?></div>
          <div class="paginacao w-inline-block">
            <div class="seta-text"><?php echo get_next_posts_link( '⟶', $wp_query->max_num_pages ); // display older posts link ?></div>
      <?php } ?>

     <?php wp_reset_query(); else : ?>
   <?php endif; ?>

Read more here: Use image as a WordPress conditional


If you know the solution of this issue, please leave us a reply in Comment section, to update the question.

Wordpress related questions and answers: