WP_Query examples

<?php

/* Tax query */
$tax_query = array();

if ( true ) {
	$tax_query[] = array(
		'taxonomy' => 'category',
		'field'    => 'slug',
		'terms'    => 'general',
	);
}

/* Meta query */
$meta_query = array();

if ( true ) {
	$meta_query[] = array(
		'key'     => '_wp_page_template',
		'value'   => 'page-templates/compact.php',
		'compare' => '='
	);
}

$query = new WP_Query(
	array(
		'post_type'        => 'page',
		'posts_per_page'   => 10,
		'meta_query'       => $meta_query,
		'tax_query'        => $tax_query,
		'no_found_rows'    => true,
		'suppress_filters' => false,
	)
);

if ( $query->have_posts() ) : ?>

	<div class="pt-posts">
		<?php while ( $query->have_posts() ) : $query->the_post(); ?>

			<div class="pt-post">
				<?php the_title(); ?>
			</div>

		<?php endwhile; ?>
	</div>

	<?php

	wp_reset_postdata();

endif;