Get All Post Types that Support a Feature in WordPress

WordPress uses post type support to make it easy to manage the feature set for custom post types. Post type support can be defined when registering a post type via register_post_type(), or after the fact via add_post_type_support(). If you would like to remove post type support, you can just use remove_post_type_support(). If you need to programmatically check and see if a post type supports a specific feature, just use post_type_supports().

However, WordPress doesn’t provide you with a simple way to fetch all post types that support a specific feature. I find that when I register support for a custom feature, I often want to add a hook for all the post types that support that new feature. So, I’ve devised the following function to do just that:

I’d love to see something like this eventually make its way into WordPress core.

Update 4/12/2016

As of WordPress 4.5, this functionality is in core! There were a few changes, most notably, the function is now called get_post_types_by_support().  It is also possible to pass in a single feature name or an array of feature names. Additionally, there is a second parameter called $operator which can be set to and (default), or or not.

Here is a sample usage:

get_post_types_by_support(array('title', 'editor'), 'or');

This will get a list of all post types that support either a title or content editor.