Twit

How to Get Your Own Post Type in WordPress by Filtering by the Right Taxonomy
How to Get Your Own Post Type in WordPress by Filtering by the Right Taxonomy

To retrieve a specific post type in WordPress filtered by a custom (or built-in) taxonomy, use the following snippet:

$Posts = get_posts(array(
	'post_type' => 'my-post-type',
	'order' => 'ASC',
	'tax_query' => array(
	array(
			'taxonomy' => 'my-taxonomy',
			'field' => 'slug',
			'terms' => 'event'
		)
	),
	'meta_query' => array(
		'AND',
		array(
			'type' => 'NUMERIC',
			'key' => 'event_date',
			'compare' => '<', 'value' => time()
		),
		array(
			'type' => 'NUMERIC',
			'key' => 'is_archive',
			'compare' => '==',
			'value' => 0
		)
	)
));

read more...