query_posts() breaks main query and causes issues. WP_Query is the proper way to create custom loops.
Wrong Way (Don’t Use):
query_posts('cat=5&posts_per_page=10');
// Breaks pagination, conflicts with main query
Right Way:
$args = array(
'post_type' => 'post',
'posts_per_page' => 10,
'category__in' => array(5)
);
$custom_query = new WP_Query($args);
if ($custom_query->have_posts()) {
while ($custom_query->have_posts()) {
$custom_query->the_post();
the_title();
the_excerpt();
}
}
wp_reset_postdata(); // Important!
Clean, doesn’t interfere with main query!
