[wp-trac] [WordPress Trac] #36652: Use meta_value in a meta query to decide type format in SQL clause
WordPress Trac
noreply at wordpress.org
Sun Jun 26 14:48:27 UTC 2016
#36652: Use meta_value in a meta query to decide type format in SQL clause
--------------------------------------------------+------------------------
Reporter: ericlewis | Owner: ericlewis
Type: enhancement | Status: reviewing
Priority: normal | Milestone: 4.6
Component: Query | Version:
Severity: normal | Resolution:
Keywords: has-patch has-unit-tests 2nd-opinion | Focuses:
--------------------------------------------------+------------------------
Comment (by ericlewis):
Awesome to see an implementation for this already :D
Replying to [comment:2 boonebgorges]:
> a. [attachment:36652.diff] opts to infer `SIGNED` when 'compare' is `=`
or `!=`.
Casting float values to `SIGNED` will make them integers, and miss
matches. e.g.
{{{
#!php
update_post_meta( 1, 'glerf', '1.1' );
$q = new WP_Query(array(
'meta_query' => (
array(
array(
'key' => 'glerf',
'value' => 1.1
)
)
)
));
}}}
> b. I'm using the term "type selector" for `%s` etc because that's what
the PHP docs use http://php.net/manual/en/function.sprintf.php. If anyone
has a better idea ("placeholder"?), shoot.
Adhering to PHP's verbiage here would be nice.
> c. Possible compat breaks are cases where one is passing numeric values
but is expecting string behavior. Eg: `"10" < "1"` (alpha sort) but `10 >
1` (numerical sort). It's only in certain corner cases that this problem
will ever arise. My guess is that the type-inferring suggested in this
ticket will cause a number of bugs like this that is far smaller than the
number of type-related bugs it'll fix. But a second opinion would be
helpful.
That's a good question. In this ticket we would introduce support for
passing the `meta_value` parameter as
an `int` or `float`, which has been supported previously, but not in the
inline documentation. The case you suggest
does seem rather edge — expecting alpha sort on comparing `10` to `1`.
''Sidenote, we should
probably change the docs for `meta_value` if we move forward here''.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/36652#comment:5>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list