Get post type from taxonomy or category page

This might be somewhat backward, but how can one get the post type being displayed on an archive page? Alternatively, how can one get the post type associated with a given taxonomy?

1 Answer
1

get_queried_object() is your friend. It will tell you all kinds of information about what your template files are trying to do. From within, you can discover your post type. Try doing a var_dump to take a look at that object.

As for your second question, taxonomy is not, as far as I know, isolated to one post_type, so that is not really something one can assume. For example, “location” may be a taxonomy to both post types: “Restaurants” and “Grocery Stores”.

Leave a Comment