wp_filter_object_list
Filters a list of objects, based on a set of key => value arguments.
Description
(array) wp_filter_object_list( (array) $list, (array) $args = array(), (string) $operator = 'and', (bool) $field = false );
Returns (array)
A list of objects or object fields.
Parameters (4)
- 0. $list (array)
- An array of objects to filter
- 1. $args — Optional. (array) =>
array()
- An array of key => value arguments to match against each object. Default empty array.
- 2. $operator — Optional. (string) =>
'and'
- 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.
- 3. $field — Optional. (bool) =>
false
- A field from the object to place instead of the entire object. Default false.
Usage
if ( !function_exists( 'wp_filter_object_list' ) ) { require_once ABSPATH . WPINC . '/functions.php'; } // An array of objects to filter $list = array(); // Optional. An array of key => value arguments to match // against each object. Default empty array. $args = array(); $operator = 'and'; // A field from the object to place instead of the entire object. // Default false. $field = false; // NOTICE! Understand what this does before running. $result = wp_filter_object_list($list, $args, $operator, $field);
Defined (1)
The function is defined in the following location(s).
- /wp-includes/functions.php
- 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();
- }