Meta Query: Revert [28659] (and [28665]) due to regressions.
props boonebgorges. fixes #29285. see #25538. git-svn-id: https://develop.svn.wordpress.org/trunk@29650 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
a8a7468a9a
commit
7c145e0bd9
|
@ -1011,7 +1011,6 @@ class WP_Meta_Query {
|
||||||
$where["key-only-$key"] = $wpdb->prepare( "$meta_table.meta_key = %s", trim( $q['key'] ) );
|
$where["key-only-$key"] = $wpdb->prepare( "$meta_table.meta_key = %s", trim( $q['key'] ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
$where_meta_key = array();
|
|
||||||
foreach ( $queries as $k => $q ) {
|
foreach ( $queries as $k => $q ) {
|
||||||
$meta_key = isset( $q['key'] ) ? trim( $q['key'] ) : '';
|
$meta_key = isset( $q['key'] ) ? trim( $q['key'] ) : '';
|
||||||
$meta_type = $this->get_cast_for_type( isset( $q['type'] ) ? $q['type'] : '' );
|
$meta_type = $this->get_cast_for_type( isset( $q['type'] ) ? $q['type'] : '' );
|
||||||
|
@ -1054,18 +1053,12 @@ class WP_Meta_Query {
|
||||||
$join[$i] .= " ON ($primary_table.$primary_id_column = $alias.$meta_id_column)";
|
$join[$i] .= " ON ($primary_table.$primary_id_column = $alias.$meta_id_column)";
|
||||||
|
|
||||||
$where[$k] = '';
|
$where[$k] = '';
|
||||||
if ( ! empty( $meta_key ) ) {
|
if ( !empty( $meta_key ) )
|
||||||
if ( isset( $q['compare'] ) ) {
|
$where[$k] = $wpdb->prepare( "$alias.meta_key = %s", $meta_key );
|
||||||
$where_meta_key[$k] = $wpdb->prepare( "$alias.meta_key = %s", $meta_key );
|
|
||||||
} else {
|
|
||||||
$where[$k] = $wpdb->prepare( "$alias.meta_key = %s", $meta_key );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( is_null( $meta_value ) ) {
|
if ( is_null( $meta_value ) ) {
|
||||||
if ( empty( $where[$k] ) && empty( $where_meta_key ) ) {
|
if ( empty( $where[$k] ) )
|
||||||
unset( $join[$i] );
|
unset( $join[$i] );
|
||||||
}
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1106,10 +1099,6 @@ class WP_Meta_Query {
|
||||||
else
|
else
|
||||||
$where = ' AND (' . implode( "\n{$this->relation} ", $where ) . ' )';
|
$where = ' AND (' . implode( "\n{$this->relation} ", $where ) . ' )';
|
||||||
|
|
||||||
if ( ! empty( $where_meta_key ) ) {
|
|
||||||
$where .= "\nAND (" . implode( "\nAND ", $where_meta_key ) . ' )';
|
|
||||||
}
|
|
||||||
|
|
||||||
$join = implode( "\n", $join );
|
$join = implode( "\n", $join );
|
||||||
if ( ! empty( $join ) )
|
if ( ! empty( $join ) )
|
||||||
$join = ' ' . $join;
|
$join = ' ' . $join;
|
||||||
|
|
|
@ -198,45 +198,6 @@ class Tests_Meta extends WP_UnitTestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function test_query_meta_query_order() {
|
|
||||||
$post1 = $this->factory->post->create( array( 'post_title' => 'meta-value-1', 'post_date' => '2007-01-01 00:00:00' ) );
|
|
||||||
$post2 = $this->factory->post->create( array( 'post_title' => 'meta-value-2', 'post_date' => '2007-01-01 00:00:00' ) );
|
|
||||||
$post3 = $this->factory->post->create( array( 'post_title' => 'meta-value-3', 'post_date' => '2007-01-01 00:00:00' ) );
|
|
||||||
|
|
||||||
add_post_meta( $post1, 'order', 1 );
|
|
||||||
add_post_meta( $post2, 'order', 2 );
|
|
||||||
add_post_meta( $post3, 'order', 3 );
|
|
||||||
|
|
||||||
$args = array(
|
|
||||||
'post_type' => 'post',
|
|
||||||
'meta_key' => 'order',
|
|
||||||
'meta_value' => 1,
|
|
||||||
'meta_compare' => '>=',
|
|
||||||
'orderby' => 'meta_value'
|
|
||||||
);
|
|
||||||
|
|
||||||
$args2 = array(
|
|
||||||
'post_type' => 'post',
|
|
||||||
'meta_key' => 'order',
|
|
||||||
'meta_value' => 1,
|
|
||||||
'meta_compare' => '>=',
|
|
||||||
'orderby' => 'meta_value',
|
|
||||||
'meta_query' => array(
|
|
||||||
'relation' => 'OR',
|
|
||||||
array(
|
|
||||||
'key' => 'order',
|
|
||||||
'compare' => '>=',
|
|
||||||
'value' => 1
|
|
||||||
)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
$posts = get_posts( $args );
|
|
||||||
$posts2 = get_posts( $args2 );
|
|
||||||
|
|
||||||
$this->assertEquals( wp_list_pluck( $posts, 'post_title' ), wp_list_pluck( $posts2, 'post_title' ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ticket 28315
|
* @ticket 28315
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in New Issue