Skip to content

Instantly share code, notes, and snippets.

@wpscholar
Created October 26, 2018 19:56
Show Gist options
  • Save wpscholar/f751f8b7a563ce6ff2ea08649691eb25 to your computer and use it in GitHub Desktop.
Save wpscholar/f751f8b7a563ce6ff2ea08649691eb25 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