CodeHQ

Query custom post type based on custom field | WordPress

<?php 
$cityname = get_field('city_name');

$args = array(
	'posts_per_page' => '100',
	'post_type' 	 => 'neighborhood',
	'meta_key'	 => 'city_n',
	'meta_value'	 => $cityname,
	'order'	         => 'asc'
);

$cityquery = new WP_Query($args);
$i = 1;
while ( $cityquery->have_posts() ) : $cityquery-> the_post();?>

WordPress pagination

//paste this where the pagination must appear

global $wp_query;
$total = $wp_query->max_num_pages;
// only bother with the rest if we have more than 1 page!
if ( $total > 1 )  {
     // get the current page
     if ( !$current_page = get_query_var('paged') )
          $current_page = 1;
     // structure of "format" depends on whether we're using pretty permalinks
     if( get_option('permalink_structure') ) {
	     $format = '&paged=%#%';
     } else {
	     $format = 'page/%#%/';
     }
     echo paginate_links(array(
          'base'     => get_pagenum_link(1) . '%_%',
          'format'   => $format,
          'current'  => $current_page,
          'total'    => $total,
          'mid_size' => 4,
          'type'     => 'list'
     ));
}
// CSS Code - add this to the style.css file
.navigation { list-style:none; font-size:12px; }
.navigation li{ display:inline; }
.navigation li a{ display:block; float:left; padding:4px 9px; margin-right:7px; border:1px solid #efefef; }
.navigation li span.current { display:block; float:left; padding:4px 9px; margin-right:7px; border:1px solid #efefef; background-color:#f5f5f5;  }	
.navigation li span.dots { display:block; float:left; padding:4px 9px; margin-right:7px;  }	

Post by taxonomy term

$terms = wp_get_post_terms( $post->ID , 'type' );

if ( $terms != null ){
 foreach( $terms as $term ) {
	$args = array(
		'post_type' => 'portfolio',
		'posts_per_page' => '3',
		'tax_query' => array (
			array (
				'taxonomy' => 'type',
				'field' => 'slug',
				'terms' =>  $term->slug
			)
		)
	);
	
}}

$query = new WP_Query($args);
$i = 1;
while ( $query->have_posts() ) : $query->
the_post(); 

A WordPress query

A WordPress query that can be amended – like below for different post types/amount of posts/categories etc – codex info here

$args = array(
	'post_type' => 'post',
	'posts_per_page' => '16',
	'orderby' => 'rand'
);

$query = new WP_Query($args);

 $i = 1;

while ( $query->have_posts() ) : $query-> the_post();