GeneratorsQueryTax Query Builder

Tax Query Builder

Taxonomy clauses that mean what you think they mean — the field matching your terms, the operator matching your intent, and one JOIN per clause accounted for.

post-tax-query.php
Saved just now
Clauses
2 clauses · 2 JOINs
Matchevery clause must match
categoryIN
include_children
IN 2 × slug
post_tagNOT IN
include_children
NOT IN 1 × slug
The query around it
no_found_rows
Skips the COUNT query, correct whenever you are not paginating.
Skip the meta cache
Right when the loop never touches post meta.
A secondary query with its own loop and wp_reset_postdata().
// Generated with WP CodeKit — powered by GrowQuest (https://growquest.io).
$args = array(
	'post_type'      => 'post',
	'posts_per_page' => 12,
	'tax_query'      => array(
		'relation' => 'AND',
		array(
			'taxonomy' => 'category',
			'field'    => 'slug',
			'terms'    => array( 'guides', 'tutorials' ),
		),
		array(
			'taxonomy' => 'post_tag',
			'field'    => 'slug',
			'terms'    => 'archived',
			'operator' => 'NOT IN',
		),
	),
);

$query = new WP_Query( $args );

if ( $query->have_posts() ) {
	echo '<ul>';

	while ( $query->have_posts() ) {
		$query->the_post();
		printf(
			'<li><a href="%1$s">%2$s</a></li>',
			esc_url( get_permalink() ),
			esc_html( get_the_title() )
		);
	}

	echo '</ul>';
	wp_reset_postdata();
} else {
	esc_html_e( 'Nothing found.', 'mytheme' );
}