web-profile

Advanced query

Get posts from category AND tag:

$new_query['tax_query'] = array(
	array(
		'taxonomy' => 'category',
		'terms' => array('cat1'),
		'field' => 'slug',
	),
	array(
		'taxonomy' => 'post_tag',
		'terms' => array('tag1'),
		'field' => 'slug',
	),
);
query_posts($new_query);

Get posts, which are NOT IN category:

$new_query['tax_query'] = array(
	array(
		'taxonomy' => 'category',
		'terms' => array('cat1', 'tag1'),
		'field' => 'slug',
		'operator' => 'NOT IN',
	),
);
query_posts($new_query);

Get posts from category OR tag:

$new_query['tax_query'] = array(
	'relation' => 'OR',
	array(
		'taxonomy' => 'category',
		'terms' => array('cat1'),
		'field' => 'slug',
	),
	array(
		'taxonomy' => 'post_tag',
		'terms' => array('tag1'),
		'field' => 'slug',
	),
);
query_posts($new_query);

Get posts from tag OR post-format:

$new_query = wp_parse_args($query_string);
$new_query['tax_query'] = array(
	'tax_query' => array(
		'relation' => 'OR',
		array(
			'taxonomy' => 'post_tag',
			'terms' => array('tag1'),
			'field' => 'slug',
		),
		array(
			'taxonomy' => 'post_format',
			'terms' => array('new-post-format'),
			'field' => 'slug',
		),
	),
) );
query_posts($new_query);

Leave a Reply

Your email address will not be published.