A loop outside the normal loop


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. <!-- loop name -->
  2. <?php $myloop = new WP_Query('category_name=CATEGORY&showposts=3');
  3. while ($myloop->have_posts()) : $myloop->the_post(); ?>
  4.  
  5. <!-- To store the IDs in a array -->
  6.  
  7.  
  8. <?php $myloop = new WP_Query('category_name=CATEGORY&showposts=3'); -->
  9. while ($myloop->have_posts()) : $myloop->the_post();
  10. &myloopids[] = $post->ID ?>
  11.  
  12. <!-- Posts in my loop but skipping the posts (IDs) in the array loop above
  13. <?php while (have_posts()) : the_post(); ?>
  14. <?php if (in_array($post->ID, $myloopIDs)) continue; update_post_caches($posts); ?>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.