WordPress at a glance

wp_filter_object_list() WP 1.0

Filters a list of objects, based on a set of key => value arguments.

Works based on: WP_List_Util::filter()
1 time — 0.000001 sec (speed of light) | 50000 times — 0.95 sec (very fast) | PHP 7.1.11, WP 4.9.8

No Hooks.

Return

Array. A list of objects or object fields.

Usage

wp_filter_object_list( $list, $args, $operator, $field );
$list(array) (required)
An array of objects to filter
$args(array)
An array of key => value arguments to match against each object.
Default: empty array
$operator(string)
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'
$field(true|false|string)
A field from the object to place instead of the entire object.
Default: false

Changelog

Since 3.0.0 Introduced.
Since 4.7.0 Uses WP_List_Util class.

Code of wp_filter_object_list() WP 5.7.2

<?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();
}

From tag: array list help functions (sorting arrays objects)

More from category: Helper Functions

No comments
    Log In