Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Get Post Types by Taxonomy in WordPress
<?php
/**
* Get all post types for a taxonomy.
*
* @author Kellen Mace
* @param string $taxonomy The taxonomy slug to get post types for.
* @return array The post types associated with $taxonomy.
*/
function wds_campbell_get_post_types_by_taxonomy( $taxonomy = '' ) {
global $wp_taxonomies;
if ( isset( $wp_taxonomies[ $taxonomy ] ) ) {
return $wp_taxonomies[ $taxonomy ]->object_type;
}
return array();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.