Back WordPress

Exclude Custom Taxonomy Term Posts from Custom Posts Query

WRITTEN BY ON 12 Jun 2014
4,668 VIEWS • SHARES
0 comments

Custom post has been a very useful capability in WordPress. It makes it much more easier to organise custom content in WordPress as a CMS. For custom post, we can use tax_query to filter unwanted categories or display custom post of certain categories. It's fully configuration and you can combine multiple query too.

For more information: WP Query - Taxonomy Parameters

$args = array(  
	'post_type' => 'custom_post_name',
	'post__not_in' => array(1,2,3),
	'order' => 'ASC',
	'posts_per_page' => 3,
	'tax_query' => array(
		array(
			'taxonomy' => 'custom_taxonomy_category',
			'field' => 'id', //slug, id, name
			'terms' => array( 1,2,3),
			'operator' => 'NOT IN' //IN, NOT IN
		),
	)	 				
);
Join the discussion

Comments will be moderated and rel="nofollow" will be added to all links. You can wrap your coding with [code][/code] to make use of built-in syntax highlighter.