[wp-trac] [WordPress Trac] #22437: Issue within WP_Meta_Query class
WordPress Trac
noreply at wordpress.org
Wed Nov 14 08:20:19 UTC 2012
#22437: Issue within WP_Meta_Query class
-----------------------------+--------------------------
Reporter: nic0tin | Type: defect (bug)
Status: new | Priority: normal
Milestone: Awaiting Review | Component: Users
Version: 3.4.2 | Severity: normal
Keywords: needs-patch |
-----------------------------+--------------------------
When making a query using WP_User_Query class while filling 'meta_query'
key with, for example, the following:
{{{
$options = array(
'meta_query' => array(
array(
'meta_key' => 'custom_field_1',
'meta_value' => '1',
'meta_compare' => '!=',
'meta_type' => 'DECIMAL'
),
array(
'meta_key' => 'custom_field_2',
'meta_value' => '',
'meta_compare' => '!='
)
)
);
$users = new WP_User_Query($options);
}}}
It doesn't consider the 'meta_query' array. I had a look into /wp-
includes/meta.php and found out that when 'WP_User_Query.parse_query_vars'
function is called, it parses the array naming keys with the 'meta_'
prefix, then it calls 'WP_User_Query.____construct' constructor which is
setting '$this->queries[]' using the 'meta_' prefix as well.
The problem appears after, into 'WP_User_Query.get_sql' function, when the
foreach loop is going through the array, it's trying to refer to array
keys without the 'meta_' prefix.
Original:
{{{
$meta_key = isset( $q['key'] ) ? trim( $q['key'] ) : '';
$meta_type = isset( $q['type'] ) ? strtoupper( $q['type'] ) : 'CHAR';
...
if ( !isset( $q['value'] ) ) {
...
$meta_value = $q['value'];
...
if ( isset( $q['compare'] ) )
$meta_compare = strtoupper( $q['compare'] );
}}}
Modified to:
{{{
$meta_key = isset( $q['meta_key'] ) ? trim( $q['meta_key'] ) : '';
$meta_type = isset( $q['meta_type'] ) ? strtoupper( $q['meta_type'] ) :
'CHAR';
...
if ( !isset( $q['meta_value'] ) ) {
...
$meta_value = $q['meta_value'];
...
if ( isset( $q['meta_compare'] ) )
$meta_compare = strtoupper( $q['meta_compare'] );
}}}
By changing to the modified version, the query was generated with expected
the INNER JOIN joints.
--
Ticket URL: <http://core.trac.wordpress.org/ticket/22437>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list