Skip to content

Instantly share code, notes, and snippets.

@alinademi
Forked from wpscholar/wp-list-find.php
Created January 29, 2021 01:40
Show Gist options
  • Save alinademi/549de64173e1e8b5927a49e95068fce1 to your computer and use it in GitHub Desktop.
Save alinademi/549de64173e1e8b5927a49e95068fce1 to your computer and use it in GitHub Desktop.
Created a function that will return the first found match from a list of items.
<?php
/**
* Find a single item in a list based on specific criteria.
*
* @uses wp_list_filter()
*
* @param array $list
* @param array $args
* @param string $operator
*
* @return mixed|null
*/
function wp_list_find( array $list, $args = array(), $operator = 'AND' ) {
$result = null;
$matches = wp_list_filter( $list, $args, $operator );
if ( $matches ) {
$result = array_shift( $matches );
}
return $result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment