title: Posts active and expired in different loops Wordpress
body: <p>I am in search of the best way to display pages active posts categories and expired after a certain period. I want to display active posts or have no expiration date in the main loop and those that expire in a loop below.</p>
  
  <p>For this I used the plugin advanced custom field ( expiration ) which define the expiration date. With loops below, I get the result I want, however, would help to improve. For example, in the loop of expired posts, the H2 tag appears on the page even if there are no expired posts, and if I move it under the condition "if ( $ exhale &lt; $ blogtime )", it appears in all expired posts, what do not want, I want to appear only once above all expired posts.</p>
  
  <p>Another question I have is whether these loops will somehow require more work from the server, since it will have to make new appointments.</p>
  
  <pre><code>    &lt;?php if ( have_posts() ) : ?&gt;
  
          &lt;?php if ( is_home() &amp;&amp; ! is_front_page() ) : ?&gt;
              &lt;header&gt;
                  &lt;h1 class="page-title screen-reader-text"&gt;&lt;?php single_post_title(); ?&gt;&lt;/h1&gt;
              &lt;/header&gt;
          &lt;?php endif; ?&gt;
  
          &lt;?php
          // Start the loop.
          while ( have_posts() ) : the_post();
          $blogtime = date( 'm/d/Y H:i:s', current_time( 'timestamp', 0 ) );
          $blogt = date( '0' );
          $expire = get_field('expiration');
              if( $expire &gt; $blogtime ) {
  
              get_template_part( 'template-parts/content', get_post_format() ); }
  
              elseif( $expire &lt; $blogt ) {
  
              get_template_part( 'template-parts/content', get_post_format() ); }
  
          // End the loop.
          endwhile;
  
      endif;
      ?&gt;
  
      &lt;?php
      $args = array( 
          'post_type' =&gt; array('post','news'), 
          'posts_per_page' =&gt; 15, 
          'cat' =&gt; $cat,
          'meta_key'   =&gt; 'expiration',
          'orderby'    =&gt; 'meta_value_num',
          'order'      =&gt; 'DESC',
      );
  
          $eventloop = new WP_Query($args);
          if ( $eventloop-&gt;have_posts() ) : 
  
              echo '&lt;h2&gt;Expired&lt;/h2&gt;';
  
              while ( $eventloop-&gt;have_posts() ) : $eventloop-&gt;the_post();
                  $blogtime = date( 'm/d/Y H:i:s', current_time( 'timestamp', 0 ) );
                  $blogt = date( '0' );
                  $expire = get_field('expiration');
  
  
                      if( $expire &lt; $blogtime ) {
  
                          if ( $expire &gt; $blogt ) {
  
                      get_template_part( 'template-parts/content', get_post_format() ); 
  
                  } }
  
              endwhile;
          endif;
      ?&gt;
  </code></pre>