Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kellenmace/0ce334f036f19c677b9e0cd0682b9ca4 to your computer and use it in GitHub Desktop.
Save kellenmace/0ce334f036f19c677b9e0cd0682b9ca4 to your computer and use it in GitHub Desktop.
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