The get_all_post_type_supports() WordPress PHP function retrieves all the features supported by a given post type.
Usage
get_all_post_type_supports( $post_type );
Example
// Get all features supported by 'custom_post_type' $features = get_all_post_type_supports( 'custom_post_type' ); print_r( $features );
Parameters
$post_type (string)– Required. The post type for which you want to retrieve the supported features.
More information
See WordPress Developer Resources: get_all_post_type_supports()
Examples
Display all supported features of a custom post type
This example retrieves and displays all supported features for a custom post type called ‘products’.
function display_supported_features() {
$features = get_all_post_type_supports( 'products' );
echo "<ul>";
foreach ( $features as $feature => $value ) {
echo "<li>" . $feature . "</li>";
}
echo "</ul>";
}
display_supported_features();
Check if a specific feature is supported by a post type
This example checks if ‘custom_post_type’ supports the ‘thumbnail’ feature.
function check_thumbnail_support() {
$features = get_all_post_type_supports( 'custom_post_type' );
if ( isset( $features['thumbnail'] ) ) {
echo "Thumbnail support is enabled.";
} else {
echo "Thumbnail support is not enabled.";
}
}
check_thumbnail_support();
Add a feature to a post type if it’s not supported
This example adds ‘excerpt’ support to ‘custom_post_type’ if it’s not already supported.
function add_excerpt_support() {
$features = get_all_post_type_supports( 'custom_post_type' );
if ( ! isset( $features['excerpt'] ) ) {
add_post_type_support( 'custom_post_type', 'excerpt' );
echo "Excerpt support added.";
} else {
echo "Excerpt support is already enabled.";
}
}
add_excerpt_support();
Remove a feature from a post type if it’s supported
This example removes ‘comments’ support from ‘custom_post_type’ if it’s supported.
function remove_comments_support() {
$features = get_all_post_type_supports( 'custom_post_type' );
if ( isset( $features['comments'] ) ) {
remove_post_type_support( 'custom_post_type', 'comments' );
echo "Comments support removed.";
} else {
echo "Comments support is not enabled.";
}
}
remove_comments_support();
Count the number of supported features for a post type
This example counts and displays the number of supported features for ‘custom_post_type’.
function count_supported_features() {
$features = get_all_post_type_supports( 'custom_post_type' );
$count = count( $features );
echo "Number of supported features: " . $count;
}
count_supported_features();