Menu

WP_Query and custom taxonomies

February 1, 2014 - wordpress

Here’s the code I am using (it’s extracted from various places in the site I am working on, but I think that’s all the essential bits):-

(1) register the new post type

register_post_type( 'history',
	array(
			'label'	=>	'History',
			'public' => true,
			'show_ui' => true,
			'publicly_queryable' => false,
			'exclude_from_search' => true,
			'hierarchical' => false,
	)
	);

(2) register the taxonomy

register_taxonomy('featured', array('page','post','history'), array(
		'hierarchical' 	=> TRUE,
		'label' 			=> 'Featured Pages',
		'singular_label'	=> 'Featured Page',
		'public' 			=> TRUE,
		'show_ui' 			=> TRUE,
		'show_tagcloud' 	=> FALSE,
		'rewrite' 			=> FALSE
	));

(3) do the query

$args = array(
		'post_type'	 =>	array('page','post','history'),
		'post_status' =>	'publish',
		'featured'	=> 'test',
	);

$wp_query = new WP_Query($args);

Leave a Reply