Different WordPress Queries

Simple loop:

<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<?php endwhile; endif; ?>

Loop with more specifications:

<?php $paged=(get_query_var('paged')) ? get_query_var('paged') : 1; query_posts(array('post_type'=>'post', 'category' => 'uncategorized', 'showposts'=>-1, 'posts_per_page' => 1, 'paged' => $paged )); ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<?php 
	$custom_field = get_post_meta($post->ID, 'custom_field', true);  
?>	
<?php endwhile; endif; ?>

WP_Query

<?php $query = new WP_Query( array(
	'numberposts'     => -1,
        'post_type'       => 'post',
	'post_status'     => 'publish',
	'category_name' => 'uncategorized'
	) );
				
if ( $query->have_posts() ) :
while ( $query->have_posts() ) : $query->the_post(); ?>
 
<?php endwhile; endif; ?>

Cached query

<?php $cache_key = 'custom-key-name';
if ( ! $query = wp_cache_get($cache_key) ) {
       $query = new WP_Query(array(
       'post_type'       => 'post',
       'post_status'     => 'publish',
) );
         
wp_cache_set($cache_key,$query,'',3600);
}
return $query; ?>

Loop within a loop

<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<?php $temp_query = $wp_query;
        $inner_query = new WP_Query( array(
	'numberposts'     => 5,
        'post_type'       => 'post',
	'post_status'     => 'publish',
	) );
				
	while ( $inner_query->have_posts() ) : $inner_query->the_post(); ?>
        <?php endwhile; ?>
<?php if (isset($wp_query)) {$wp_query = $temp_query;} ?>
<?php endwhile; endif; ?>

Loop through each term within a taxonomy and query their posts

<?php $tax_terms = get_terms( array('TAXONOMY_NAME') );
foreach ($tax_terms as $term) :
    $term_slug = $term->slug;
    $query = new WP_Query( array(
                'post_type' => 'POST_TYPE_NAME',
                'posts_per_page' => 5, 
                'tax_query' => array(
                    array(
                        'taxonomy' => 'TAXONOMY_NAME',
                        'field'    => 'slug',
                        'terms'    => $term_slug,
                    ),
                ),
            ));
    if( $query->have_posts() ) : while ( $query->have_posts() ) : $query->the_post(); ?>
            
    <?php endwhile; endif;
endforeach; ?>