Skip to main content
Home / Code Snippets / WordPress / Run Loop on Posts of Specific Category

Run Loop on Posts of Specific Category

<?php query_posts('cat=5'); ?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
   <?php the_content(); ?>
<?php endwhile; endif; ?>

If you were to use this, for example, in a left sidebar which ran before the main loop on your page, remember to reset the query or it will upset that main loop.

<?php wp_reset_query(); ?>
icon-link icon-logo-star icon-search icon-star