Using WordPress ‘get_post_types_by_support()’ PHP function

The get_post_types_by_support() WordPress PHP function retrieves a list of post type names that support a specific feature.

Usage

get_post_types_by_support( $feature, $operator = 'and' )

Example: get_post_types_by_support( 'thumbnail' );

Parameters

  • $feature (array|string) (Required): Single feature or an array of features the post types should support.
  • $operator (string) (Optional): The logical operation to perform. 'or' means only one element from the array needs to match; 'and' means all elements must match; 'not' means no elements may match. Default 'and'.

More information

See WordPress Developer Resources: get_post_types_by_support()

Examples

Get post types with thumbnail support

This example retrieves all post types that support the thumbnail feature.

// Get post types with thumbnail support
$post_types = get_post_types_by_support( 'thumbnail' );

Get post types supporting multiple features with ‘and’ operator

This example retrieves all post types that support both the title and editor features.

// Get post types with title and editor support
$post_types = get_post_types_by_support( array( 'title', 'editor' ) );

Get post types supporting multiple features with ‘or’ operator

This example retrieves all post types that support either the title or editor feature.

// Get post types with title or editor support
$post_types = get_post_types_by_support( array( 'title', 'editor' ), 'or' );

Get post types not supporting a specific feature

This example retrieves all post types that do not support the comments feature.

// Get post types without comments support
$post_types = get_post_types_by_support( 'comments', 'not' );

Get post types with custom taxonomy support

This example retrieves all post types that support a custom taxonomy called my_custom_taxonomy.

// Get post types with my_custom_taxonomy support
$post_types = get_post_types_by_support( 'my_custom_taxonomy' );