如何按贴子类型获取所有`supports`属性?

时间:2018-12-15 作者:T.Todua

i、 e.当post注册时,如下所示:

$args= [
  \'supports\' => [\'thumbnail\', \'title\', \'post-formats\'  ...]
]
如果以后,我想得到所有supports 属性,我应该使用哪个函数?i、 e.类似于get_supports(\'post\');

2 个回复
最合适的回答,由SO网友:birgire 整理而成

存在get_all_post_type_supports() 获取给定帖子类型的支持功能。这是一个包装_wp_post_type_features 全局变量:

/**
 * 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();
}
示例:这里有一个来自wp shell的\'post\' 岗位类型:

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
)
另一个有用的包装是get_post_types_by_support().

SO网友:T.Todua

我选择使用$GLOBALS[\'_wp_post_type_features\'], 返回的结果如下:

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
        )
 ...

相关推荐

Admin Theme customization

我遵循wordpress codex网站上关于通过插件创建管理主题的说明。我激活了插件,但我的样式表没有包含在<head>.. 这是我的代码:add_action( \'admin_init\', \'kd_plugin_admin_init\' ); add_action( \'admin_menu\', \'kd_plugin_admin_menu\' ); function kd_plugin_admin_init() { /* Register