[wp-trac] [WordPress Trac] #47286: WP_Query final SQL replaces int numbers to string in meta_query
WordPress Trac
noreply at wordpress.org
Wed May 15 22:58:42 UTC 2019
#47286: WP_Query final SQL replaces int numbers to string in meta_query
--------------------------+-----------------------------
Reporter: eddr | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Query | Version: 5.2
Severity: normal | Keywords:
Focuses: |
--------------------------+-----------------------------
WP_Query meta_query numeric value results in comparison to a string value
1.
{{{#!php
<?php
function intercept_query_clauses( $pieces )
{
var_dump( $pieces );
return $pieces;
}
add_filter( 'posts_where', 'intercept_query_clauses', 1, 1 );
$query_args = [
'meta_query' => [[
'key' => 'key',
'value' => 10,
'compare' => "="
]]
, 'fields' => 'ids'
];
$query = new WP_Query( $query_args );
}}}
result:
**AND (
( wp_postmeta.meta_key = 'key' AND ''wp_postmeta.meta_value = '10''' )
) AND wp_posts.post_type = 'post' AND (wp_posts.post_status = 'publish' OR
wp_posts.post_status = 'private')**
2. using 'type' => numeric results in
**AND (
( wp_postmeta.meta_key = 'key' AND ''CAST(wp_postmeta.meta_value AS
SIGNED)'' = '10' )
) AND wp_posts.post_type = 'post' AND (wp_posts.post_status = 'publish' OR
wp_posts.post_status = 'private')"**
which doesn't solve the problem + why casting the field and not the value?
Am I missing something big here?
Thanks
--
Ticket URL: <https://core.trac.wordpress.org/ticket/47286>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list