i.e. when post is registered, like this:
$args= [
'supports' => ['thumbnail', 'title', 'post-formats' ...]
]
If later, I want to get all supports
attribute for specific post type, which function should I use? i.e. something like get_supports('post');
i.e. when post is registered, like this:
$args= [
'supports' => ['thumbnail', 'title', 'post-formats' ...]
]
If later, I want to get all supports
attribute for specific post type, which function should I use? i.e. something like get_supports('post');
There exists the get_all_post_type_supports()
to get the supported features for a given post type. It's a wrapper for the _wp_post_type_features
global variable:
/**
* Get all the post type features
*
* @since 3.4.0
*
* @global array $_wp_post_type_features
*
* @param string $post_type The post type.
* @return array Post type supports list.
*/
function get_all_post_type_supports( $post_type ) {
global $_wp_post_type_features;
if ( isset( $_wp_post_type_features[$post_type] ) )
return $_wp_post_type_features[$post_type];
return array();
}
Here's an usage example from the wp shell for the 'post'
post type:
wp> print_r( get_all_post_type_supports( 'post' ) );
Array
(
[title] => 1
[editor] => 1
[author] => 1
[thumbnail] => 1
[excerpt] => 1
[trackbacks] => 1
[custom-fields] => 1
[comments] => 1
[revisions] => 1
[post-formats] => 1
)
Another useful wrapper is get_post_types_by_support()
.
I've chosen to use $GLOBALS['_wp_post_type_features']
, that returns like this:
Array
(
[post] => Array
(
[title] => 1
[editor] => 1
[author] => 1
[thumbnail] => 1
[excerpt] => 1
[trackbacks] => 1
[custom-fields] => 1
[comments] => 1
[revisions] => 1
[post-formats] => 1
)
[page] => Array
(
[title] => 1
[editor] => 1
[author] => 1
[thumbnail] => 1
[page-attributes] => 1
[custom-fields] => 1
[comments] => 1
[revisions] => 1
)
...