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

  1. if ( !function_exists( 'wp_filter_object_list' ) ) { 
  2. require_once ABSPATH . WPINC . '/functions.php'; 
  3.  
  4. // An array of objects to filter 
  5. $list = array(); 
  6.  
  7. // Optional. An array of key => value arguments to match 
  8. // against each object. Default empty array. 
  9. $args = array(); 
  10. $operator = 'and'; 
  11.  
  12. // A field from the object to place instead of the entire object. 
  13. // Default false. 
  14. $field = false; 
  15.  
  16. // NOTICE! Understand what this does before running. 
  17. $result = wp_filter_object_list($list, $args, $operator, $field); 
  18.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/functions.php  
  1. function wp_filter_object_list( $list, $args = array(), $operator = 'and', $field = false ) { 
  2. if ( ! is_array( $list ) ) { 
  3. return array(); 
  4.  
  5. $util = new WP_List_Util( $list ); 
  6.  
  7. $util->filter( $args, $operator ); 
  8.  
  9. if ( $field ) { 
  10. $util->pluck( $field ); 
  11.  
  12. return $util->get_output();