admin管理员组文章数量:1130349
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');
2 Answers
Reset to default 4There 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();
}
Example:
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
)
...
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');
2 Answers
Reset to default 4There 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();
}
Example:
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
)
...
本文标签: customizationHow to get all supports attributes by post type
版权声明:本文标题:customization - How to get all `supports` attributes by post type? 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749096679a2315364.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论