WordPress at a glance

wp_filter_object_list() WP 1.0

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

Notes:

  • Since 4.7.0 Uses WP_List_Util class.
Is the basis for: get_post_stati()
Works based on: WP_List_Util()
✈ 1 time = 0.000001s = speed of light | 50000 times = 0.95s = 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

Code of wp_filter_object_list: wp-includes/functions.php VER 4.9.8

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

Related Functions

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

More from category: Helper Functions

No comments
    Hello, !     Log In . Register