Only get post types based on support

I found out that get_post_types_by_support() seems to be the solution to get the desired result:

$post_types = get_post_types_by_support(array('title', 'editor', 'thumbnail'));

The above will return post, page and any custom post type that supports title, editor and thumbnail.

Since this will also return private post types, we could loop through the list and check if the type is viewable at the frontend. This can be done by using the is_post_type_viewable() function:

foreach ($post_types as $key => $post_type) {
  if (!is_post_type_viewable($post_type)) {
    unset($post_types[$post_type]);
  }
}

Leave a Comment