获取发布类型对象(一串 $帖子类型 ):工作包_支柱_类型|空

按名称检索帖子类型对象。

说明

另请参见

参数

$帖子类型一串必修的
注册帖子类型的名称。

返回

工作包_支柱_类型|空 工作包_支柱_类型对象,否则为null。

来源

函数get_post_type_object($post_type){全局$wp_post_types;如果(!is_scalar($post_type)||为空($wp_post_types[$post_type]){返回null;}返回$wp_post_types[$post_type];}

变更日志

版本说明
4.6.0返回的对象现在是的实例工作包_支柱_类型.
3.0.0介绍。

用户贡献的笔记

  1. 跳到注释3内容

    示例

    $obj=获取post_type_object('post');echo$obj->labels->singular_name;

    从技术上讲,这与

    全局$wp_post_types;$obj=$wp_post_types['post'];echo$obj->labels->singular_name;

    打印($obj)可能会返回如下内容:

    stdClass对象([labels]=>stdClass对象([name]=>帖子[singular_name]=>帖子[add_new]=>添加新[add_new_item]=>添加新帖子[edit_item]=>编辑帖子[new_item]=>新建帖子[view_item]=>查看文章[search_items]=>搜索帖子[not_found]=>未找到帖子[not_found_in_trash]=>垃圾箱中找不到帖子[parent_item_colon]=>)[描述]=>[公开查询]=>1[exclude_from_search]=>[_builtin]=>1[_edit_link]=>post.php?帖子=%d[capability_type]=>岗位[层次结构]=>[公开]=>1[重写]=>[查询变量]=>[寄存器_ meta _ box _ cb]=>[分类法]=>数组()[show_ui]=>1[菜单位置]=>[菜单_图标]=>[永久链接任务]=>1[取消导出]=>1[show_in_nav_menus]=>1[姓名]=>职位[cap]=>stdClass对象([编辑_发布]=>编辑_发布[编辑文章]=>编辑文章[edit_others_posts]=>编辑其他帖子[publish_posts]=>发布posts[read_post]=>读post[read_private_posts]=>读取隐私[delete_post]=>删除帖子)[label]=>帖子)

    假设我们有岗位类型“认证”,我们可以这样做:

    $obj=get_post_type_object('认证');

    打印($obj)可能会返回如下内容:

    stdClass对象([labels]=>stdClass对象([名称]=>认证[singular_name]=>认证[add_new]=>添加新[add_new_item]=>添加新证书[edit_item]=>编辑证书[new_item]=>新建页面[view_item]=>查看认证[search_items]=>搜索证书[not_found]=>找不到[not_found_in_trash]=>垃圾箱中找不到[parent_item_colon]=>家长认证:[all_items]=>所有认证[菜单名称]=>认证[update_item]=>更新认证[name_admin_bar]=>认证)[description]=>认证[公开]=>1[层次结构]=>1[exclude_from_search]=>[公开查询]=>1[show_ui]=>1[显示_菜单]=>[show_in_nav_menus]=>1[show_in_admin_bar]=>1[菜单位置]=>5[menu_icon]=>dashicons-welcome-widgets-menus[capability_type]=>岗位[map_meta_cap]=>1[寄存器_ meta _ box _ cb]=>[分类法]=>数组([0]=>目标)[has_archive]=>1[重写]=>数组([slug]=>认证[前面有]=>1[页数]=>1[馈送]=>1[ep_mask]=>1)[query_var]=>认证[取消导出]=>1[delete_with_user]=>[内置]=>[_edit_link]=>post.php?帖子=%d[标签]=>认证[名称]=>认证[cap]=>stdClass对象([编辑_发布]=>编辑_发布[read_post]=>读post[delete_post]=>删除帖子[edit_posts]=>编辑_posts[edit_others_posts]=>编辑其他帖子[publish_posts]=>发布posts[read_private_posts]=>读取隐私[读取]=>读取[delete_posts]=>删除帖子[delete_private_posts]=>删除私有主机[delete_published_posts]=>删除发布的posts[delete_others_posts]=>删除其他帖子[edit_private_posts]=>编辑隐私[编辑发布文章]=>编辑发布文章[创建帖子]=>编辑帖子))

    请注意,对象的属性名称与寄存器post_type()功能。

  2. 跳到注释4内容

    示例

    检索段塞

    $current_queried_post_type_slug=get_post_type_object(get_post_type())->重写['slug'];

    显示slug:

    echo$current_queried_post_type_slug;

    构建post_type的URL:

    echo home_url(“/”.$current_queried_post_type_slug.“/”);

你必须登录在能够贡献笔记或反馈之前。