All Posts Without A Specific Term

Find Meta Query syntax to help you find records that are ’empty’ as well as not matching an existing set.

Querying for a post, or custom post type, that does not have a specific tag or other taxonomy term, is slightly tricky as we must include those without a tag.

	//Get posts in "industry" CPT where tag slug is not "foods"
	$pods = pods( 'industry', array(
		'where' => '(post_tag.name != "foods") OR (post_tag.name IS NULL)' )
	);

	//Get posts in "industry" CPT where tag ID is not "foods"
	$pods = pods( 'industry', array(
			'where' => '(post_tag.term_id != "7") OR (post_tag.name IS NULL)' )
	);

We can also use this “meta” syntax:

	$params = array (
		'where' =>
			array (
				'relation' => 'OR',
					array (
						'field' => 'post_tag.name',
						'value' =>
							array (
								0 => 'foods',
							),
						'compare' => 'IN',
					),
					array (
						'field' => 'post_tag.name',
						'value' =>
							array (
								0 => 'NULL',
							),
						'compare' => 'NOT IN',
					),
			),
	);
	$pods = pods( 'industry', $params );

Questions