Get The Post Type A Taxonomy Is Attached To

If we peek into the global $wp_taxonomies variable we see the associated object types.

There might be better ways to do this or even core functions, but you could try the following:

function wpse_172645_get_post_types_by_taxonomy( $tax = 'category' )
{
    global $wp_taxonomies;
    return ( isset( $wp_taxonomies[$tax] ) ) ? $wp_taxonomies[$tax]->object_type : array();
}

then for the default setup you get:

$out = wpse_172645_get_post_types_by_taxonomy( 'category' );
print_r( $out );

with the output:

Array
(
    [0] => post
)

Leave a Comment

tech