0

Im a nubie and I wrote these lines of code and I'm thinking Im creating some sort of problem because I often get a message in event viewer saying: A process serving application pool 'DefaultAppPool' exceeded time limits during shut down. Probably a memory leak or something.But This is my code:

<?php
global $post;
$args = array( 'posts_per_page' => 1,
 'offset'=> 0,
 'category' => 16,
 'category_name'    => 'Main article',  
 );
$myposts = get_posts( $args );
foreach ( $myposts as $post ) : 
  setup_postdata( $post ); 
  ?>
    <div class="categoriesStyle"><?php exclude_post_categories("40"); ?></div>
     <div class="first"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></div>
     <div class="paddingSpace"></div>
     <div class="tagOffice"><span style="color: #27ae60"><i class="fa fa-globe" aria-hidden="true"></i> <?php the_tags(''); ?></span></div>
     <div class="paddingSpace"></div>
    <div class="contentText"><span style="color: #000"><?php echo intro_text(150); ?></span></div>
    <hr class="style-two">
<?php endforeach;
wp_reset_postdata(); ?>


    <?php
global $post;
$args = array( 'posts_per_page' => 1, 'offset'=> 1, 'category' => 16, 'category_name'    => 'Main article'   );
$myposts = get_posts( $args );
foreach ( $myposts as $post ) : 
  setup_postdata( $post ); 
  ?>
 <div class="categoriesStyle"><?php exclude_post_categories("40"); ?></div>
    <div class="second"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></div>
    <div class="paddingSpace"></div>
     <div class="tagOffice"><span style="color: #27ae60"><i class="fa fa-globe" aria-hidden="true"></i> <?php the_tags(''); ?></span></div>
     <div class="paddingSpace"></div>
    <div class="contentText"><span style="color: #000"><?php echo intro_text(150); ?></span></div>
    <hr class="style-two">
<?php endforeach;
wp_reset_postdata(); ?>
  • 1
    The only real problem you have with this type of example is that a single query could grab all of the posts you need - running 1 query is faster than 2 queries - then use a counter inside your foreach loop, and you can mark them up however you need. Though CSS :nth-child(even) and :nth-child(odd) are probably better than having a <div class="second". Have you tried using a query optimization plugin that will show you which queries are being run and how long they're taking? – WebElaine Apr 30 '18 at 21:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.