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函式,用於檢索所有註冊的文章型別的陣列: 這個函式不接受任何引數,返回一個陣列的文章型別物件。

獲得所有註冊的文章型別物件的列表。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
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 );
}
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 ); }
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
檢視更多 >