Switch language

wpseek.com
A WordPress-centric search engine for devs and theme authors




wp_list_filter [ WordPress Function ]

wp_list_filter ( $list, $args = array(), $operator = 'AND' )
Parameters:
  • (array) $list An array of objects to filter
  • (array) $args An array of key => value arguments to match against each object
  • (string) $operator The logical operation to perform: 'AND' means all elements from the array must match; 'OR' means only one element needs to match; 'NOT' means no elements may match. The default is 'AND'.
Returns:
  • (array)
Defined at:



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

Source


<?php
function wp_list_filter$list$args = array(), $operator 'AND' ) {
    if ( ! 
is_array$list ) )
        return array();

    if ( empty( 
$args ) )
        return 
$list;

    
$operator strtoupper$operator );
    
$count count$args );
    
$filtered = array();

    foreach ( 
$list as $key => $obj ) {
        
$to_match = (array) $obj;

        
$matched 0;
        foreach ( 
$args as $m_key => $m_value ) {
            if ( 
$m_value == $to_match$m_key ] )
                
$matched++;
        }

        if ( ( 
'AND' == $operator && $matched == $count )
          || ( 
'OR' == $operator && $matched )
          || ( 
'NOT' == $operator && == $matched ) ) {
            
$filtered[$key] = $obj;
        }
    }

    return 
$filtered;
}
?>

Examples [ wp-snippets.com ]

Top Google zoekresultaten

Meer ...

Gebruikersdiscussies [ wordpress.org ]

0 User Note(s)

Nog geen één. Wees de eerste!

Nieuw toevoegen ...



HTML5 Powered with CSS3 / Styling, Performance & Integration, and Semantics