Add NOT LIKE/BETWEEN/IN. props AaronCampbell, fixes #9124.
git-svn-id: https://develop.svn.wordpress.org/trunk@15755 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
500d2be317
commit
b040a1790a
|
@ -275,7 +275,7 @@ class WP {
|
||||||
|
|
||||||
if ( !empty( $this->query_vars[$wpvar] ) ) {
|
if ( !empty( $this->query_vars[$wpvar] ) ) {
|
||||||
if ( ! is_array( $this->query_vars[$wpvar] ) ) {
|
if ( ! is_array( $this->query_vars[$wpvar] ) ) {
|
||||||
$this->query_vars[$wpvar] = (string) $this->query_vars[$wpvar];
|
$this->query_vars[$wpvar] = (string) $this->query_vars[$wpvar];
|
||||||
} else {
|
} else {
|
||||||
foreach ( $this->query_vars[$wpvar] as $vkey => $v )
|
foreach ( $this->query_vars[$wpvar] as $vkey => $v )
|
||||||
$this->query_vars[$wpvar][$vkey] = (string) $v;
|
$this->query_vars[$wpvar][$vkey] = (string) $v;
|
||||||
|
@ -550,11 +550,11 @@ class WP_Object_Query {
|
||||||
* A query is an associative array:
|
* A query is an associative array:
|
||||||
* - 'key' string The meta key
|
* - 'key' string The meta key
|
||||||
* - 'value' string|array The meta value
|
* - 'value' string|array The meta value
|
||||||
* - 'compare' (optional) string How to compare the key to the value.
|
* - 'compare' (optional) string How to compare the key to the value.
|
||||||
* Possible values: '=', '!=', '>', '>=', '<', '<=', 'LIKE', 'IN', 'BETWEEN'.
|
* Possible values: '=', '!=', '>', '>=', '<', '<=', 'LIKE', 'NOT LIKE', 'IN', 'NOT IN', 'BETWEEN', 'NOT BETWEEN'.
|
||||||
* Default: '='
|
* Default: '='
|
||||||
* - 'type' string (optional) The type of the value.
|
* - 'type' string (optional) The type of the value.
|
||||||
* Possible values: 'NUMERIC', 'BINARY', 'CHAR', 'DATE', 'DATETIME', 'DECIMAL', 'SIGNED', 'TIME', 'UNSIGNED'.
|
* Possible values: 'NUMERIC', 'BINARY', 'CHAR', 'DATE', 'DATETIME', 'DECIMAL', 'SIGNED', 'TIME', 'UNSIGNED'.
|
||||||
* Default: 'CHAR'
|
* Default: 'CHAR'
|
||||||
*
|
*
|
||||||
* @since 3.1.0
|
* @since 3.1.0
|
||||||
|
@ -573,9 +573,9 @@ class WP_Object_Query {
|
||||||
* Possible values: 'term_id', 'slug' or 'name'
|
* Possible values: 'term_id', 'slug' or 'name'
|
||||||
* Default: 'slug'
|
* Default: 'slug'
|
||||||
* - 'operator' string (optional)
|
* - 'operator' string (optional)
|
||||||
* Possible values: 'IN' and 'NOT IN'.
|
* Possible values: 'IN' and 'NOT IN'.
|
||||||
* Default: 'IN'
|
* Default: 'IN'
|
||||||
* - 'include_children' bool (optional) Wether to include child terms.
|
* - 'include_children' bool (optional) Wether to include child terms.
|
||||||
* Default: true
|
* Default: true
|
||||||
*
|
*
|
||||||
* @since 3.1.0
|
* @since 3.1.0
|
||||||
|
@ -636,7 +636,7 @@ class WP_Object_Query {
|
||||||
$meta_compare = isset( $q['compare'] ) ? strtoupper( $q['compare'] ) : '=';
|
$meta_compare = isset( $q['compare'] ) ? strtoupper( $q['compare'] ) : '=';
|
||||||
$meta_type = isset( $q['type'] ) ? strtoupper( $q['type'] ) : 'CHAR';
|
$meta_type = isset( $q['type'] ) ? strtoupper( $q['type'] ) : 'CHAR';
|
||||||
|
|
||||||
if ( ! in_array( $meta_compare, array( '=', '!=', '>', '>=', '<', '<=', 'LIKE', 'IN', 'BETWEEN' ) ) )
|
if ( ! in_array( $meta_compare, array( '=', '!=', '>', '>=', '<', '<=', 'LIKE', 'NOT LIKE', 'IN', 'NOT IN', 'BETWEEN', 'NOT BETWEEN' ) ) )
|
||||||
$meta_compare = '=';
|
$meta_compare = '=';
|
||||||
|
|
||||||
if ( 'NUMERIC' == $meta_type )
|
if ( 'NUMERIC' == $meta_type )
|
||||||
|
@ -658,7 +658,7 @@ class WP_Object_Query {
|
||||||
if ( !empty( $meta_key ) )
|
if ( !empty( $meta_key ) )
|
||||||
$where .= $wpdb->prepare( " AND $alias.meta_key = %s", $meta_key );
|
$where .= $wpdb->prepare( " AND $alias.meta_key = %s", $meta_key );
|
||||||
|
|
||||||
if ( in_array( $meta_compare, array( 'IN', 'BETWEEN' ) ) ) {
|
if ( in_array( $meta_compare, array( 'IN', 'NOT IN', 'BETWEEN', 'NOT BETWEEN' ) ) ) {
|
||||||
if ( ! is_array( $meta_value ) )
|
if ( ! is_array( $meta_value ) )
|
||||||
$meta_value = preg_split( '/[,\s]+/', $meta_value );
|
$meta_value = preg_split( '/[,\s]+/', $meta_value );
|
||||||
} else {
|
} else {
|
||||||
|
@ -668,14 +668,14 @@ class WP_Object_Query {
|
||||||
if ( empty( $meta_value ) )
|
if ( empty( $meta_value ) )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if ( 'IN' == $meta_compare ) {
|
if ( 'IN' == substr( $meta_compare, -2) ) {
|
||||||
$meta_field_types = substr( str_repeat( ',%s', count( $meta_value ) ), 1 );
|
$meta_field_types = substr( str_repeat( ',%s', count( $meta_value ) ), 1 );
|
||||||
$meta_compare_string = "($meta_field_types)";
|
$meta_compare_string = "($meta_field_types)";
|
||||||
unset( $meta_field_types );
|
unset( $meta_field_types );
|
||||||
} elseif ( 'BETWEEN' == $meta_compare ) {
|
} elseif ( 'BETWEEN' == substr( $meta_compare, -7) ) {
|
||||||
$meta_value = array_slice( $meta_value, 0, 2 );
|
$meta_value = array_slice( $meta_value, 0, 2 );
|
||||||
$meta_compare_string = '%s AND %s';
|
$meta_compare_string = '%s AND %s';
|
||||||
} elseif ( 'LIKE' == $meta_compare ) {
|
} elseif ( 'LIKE' == substr( $meta_compare, -4 ) ) {
|
||||||
$meta_value = '%' . like_escape( $meta_value ) . '%';
|
$meta_value = '%' . like_escape( $meta_value ) . '%';
|
||||||
$meta_compare_string = '%s';
|
$meta_compare_string = '%s';
|
||||||
} else {
|
} else {
|
||||||
|
@ -708,7 +708,7 @@ class WP_Object_Query {
|
||||||
$query['include_children'] = true;
|
$query['include_children'] = true;
|
||||||
|
|
||||||
$query['do_query'] = false;
|
$query['do_query'] = false;
|
||||||
|
|
||||||
$sql_single = get_objects_in_term( $query['terms'], $query['taxonomy'], $query );
|
$sql_single = get_objects_in_term( $query['terms'], $query['taxonomy'], $query );
|
||||||
|
|
||||||
if ( empty( $sql_single ) )
|
if ( empty( $sql_single ) )
|
||||||
|
|
Loading…
Reference in New Issue