get_post_types

函数
get_post_types ( $args = array(), $output = 'names', $operator = 'and' )
参数
  • (array|string) $args Optional. An array of key => value arguments to match against the post type objects. Default empty array.
    Required:
    Default: array()
  • (string) $output Optional. The type of output to return. Accepts post type 'names' or 'objects'. Default 'names'.
    Required:
    Default: 'names'
  • (string) $operator Optional. The logical operation to perform. 'or' means only one element from the array needs to match; 'and' means all elements must match; 'not' means no elements may match. Default 'and'.
    Required:
    Default: 'and'
返回值
  • (string[]|WP_Post_Type[]) An array of post type names or objects.
相关
  • register_post_type()
定义位置
相关方法
get_post_typeset_post_typeget_post_mime_typesget_post_statesget_post_type_labels
引入
2.9.0
弃用
-

get_post_types函数是一个WordPress函数,用于检索所有注册的文章类型的数组: 这个函数不接受任何参数,返回一个数组的文章类型对象。

获得所有注册的文章类型对象的列表。

function get_post_types( $args = array(), $output = 'names', $operator = 'and' ) {
	global $wp_post_types;

	$field = ( 'names' === $output ) ? 'name' : false;

	return wp_filter_object_list( $wp_post_types, $args, $operator, $field );
}

常见问题

FAQs
查看更多 >