Exclude or Include by custom field values
Last updated
$args['post_meta_filter'] = array(
array(
'key' => 'age', // meta key
'value' => array( 3, 4 ), // mixed|array
// @param string|array compare
// Numeric Operators
// '<' -> less than
// '>' -> more than
// '<>' -> not equals
// '=' -> equals
// 'BETWEEN' -> between two values
// String Operators
// 'LIKE'
// 'NOT LIKE'
//
'operator' => 'BETWEEN',
'allow_missing' => true // allow match if this custom field is unset
)
// .. additional rules ..
);add_filter('asp_query_args', 'asp_add_my_meta_filter', 10, 1);
function asp_add_my_meta_filter( $args ) {
$args['post_meta_filter'][] = array(
'key' => 'my_field',
'value' => 1,
'operator' => '<>',
'allow_missing' => true
);
return $args;
}