get_post_types()获取所有的文章类型

目录

描述

Returns the registered post types as found in $wp_post_types.

get_post_types() 描述

用法

 <?php get_post_types$args$output$operator ?> 

get_post_types() 用法

参数

$args

(array) (可选) An array of key value arguments to match against the post types.

默认值: array()

Some of these include:

  • public - Boolean. If true, only public post types will be returned.
  • publicly_queryable - Boolean
  • exclude_from_search - Boolean
  • show_ui - Boolean
  • capability_type
  • hierarchical
  • menu_position
  • menu_icon
  • permalink_epmask
  • rewrite
  • query_var
  • _builtin - Boolean. If true, will return WordPress default post types. Use false to return only custom post types.

$output

(string) (可选) The type of output to return, either 'names' or 'objects'.

默认值: 'names'

$operator

(string) (可选) Operator (and/or) to use with multiple $args.

默认值: 'and'

get_post_types() 参数

返回值

array 

A list of post names or objects.

get_post_types() 返回值

示例

Default Usage

The call to get post types returns the registered post types.

Output a list all registered post types

Output a list of all public custom post types

The built-in public post types are post, page, and attachment. By setting '_builtin' to false, we will exclude them and show only the custom public post types.

Output a named post type

This example uses the 'object' output to retrieve the post type called 'property':

get_post_types() 示例

注意

Be careful when retrieving "public" custom post-types that were registered using the register_post_type() function: the inputs to the register_post_type function are not intelligently processed, so if you verbosely set options for publicly_queriable, show_ui, show_in_nav_menus, and exclude_from_search, this is NOT considered equivalent to setting the public option and querying for public post-types will not yield results that were defined with the equivalent explicit arguments. See bug 18950.

WordPress builtin post types:

  • post - WordPress built-in post type
  • page - WordPress built-in post type
  • attachment - WordPress built-in post type
  • revision - WordPress built-in post type
  • nav_menu_item - WordPress built-in post type (Since 3.0)
  • custom post type - any custom post type (Since 3.0)

get_post_types() 注意

历史

  • 3.0 :
    • 添加 operator parameter.
  • 添加于 版本: 2.9

get_post_types() 历史

源文件

get_post_types() 函数的代码位于 wp-includes/post.php.

get_post_types() 源文件

相关