wp_filter_object_list

函式
wp_filter_object_list ( $list, $args = array(), $operator = 'and', $field = false )
引數
  • (array) $list An array of objects to filter.
    Required:
  • (array) $args Optional. An array of key => value arguments to match against each object. Default empty array.
    Required:
    Default: array()
  • (string) $operator Optional. The logical operation to perform. 'AND' means all elements from the array must match. 'OR' means only one element needs to match. 'NOT' means no elements may match. Default 'AND'.
    Required:
    Default: 'and'
  • (bool|string) $field Optional. A field from the object to place instead of the entire object. Default false.
    Required:
    Default: false
返回值
  • (array) A list of objects or object fields.
定義位置
相關方法
wp_filter_oembed_resultwp_terms_checklistwp_filter_nohtml_kseswp_filter_post_kseswp_get_object_terms
引入
3.0.0
棄用
-

wp_filter_object_list:這個過濾器用於在顯示前修改一個物件的陣列。它把物件陣列作為一個引數,並返回修改後的陣列。

根據一組key => value引數,過濾一個物件的列表。

檢索列表中符合給定引數的物件。key代表屬性名稱,value代表屬性值。

如果一個物件有比引數中指定的更多的屬性,這不會使它失去資格: 當使用’AND’運算子時,任何缺失的屬性都會使它失去資格。

當使用`$field`引數時,這個函式也可以從所有匹配的物件中檢索出一個特定的欄位,而wp_list_filter()只做過濾。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function wp_filter_object_list( $list, $args = array(), $operator = 'and', $field = false ) {
if ( ! is_array( $list ) ) {
return array();
}
$util = new WP_List_Util( $list );
$util->filter( $args, $operator );
if ( $field ) {
$util->pluck( $field );
}
return $util->get_output();
}
function wp_filter_object_list( $list, $args = array(), $operator = 'and', $field = false ) { if ( ! is_array( $list ) ) { return array(); } $util = new WP_List_Util( $list ); $util->filter( $args, $operator ); if ( $field ) { $util->pluck( $field ); } return $util->get_output(); }
function wp_filter_object_list( $list, $args = array(), $operator = 'and', $field = false ) {
	if ( ! is_array( $list ) ) {
		return array();
	}

	$util = new WP_List_Util( $list );

	$util->filter( $args, $operator );

	if ( $field ) {
		$util->pluck( $field );
	}

	return $util->get_output();
}

常見問題

FAQs
檢視更多 >