Plugin Author
TC.K
(@wp_dummy)
What is your meaning by
it won’t include keys in the table
.
what is the table?? Table in the plugin page Custom Meta Field?
If this is what you mean, then it is okay on my test.
Maybe it crashed with other plugin that you activated?
Hey ron_dev,
Sorry for not being clear… The table I’m referring to is the wp_postmeta table.
So I have a meta_value stored in the wp_postmeta table as “2.5” and lets say I have my options value setup at “2.0|2.5|3.0|3.5|4.0” with a compare setting of “>=” When I choose 2.5 from the drop down the corresponding value (post_id) tied to the 2.5 value is not showing in the search results. It seems like it wasn’t looking for double precision values.
I’ll double check again tonight. I may have something setup wrong…
Plugin Author
TC.K
(@wp_dummy)
@lifeinthegrid,
I got the problem. Now try the latest version 1.0.6. It should be okay now.
Hi @ron_dev
Thanks for the quick response! That didn’t work either. However in the function get_wqsf_cmf. I commented out all of the references to:
‘type’ =>
and it seems to work at first pass, but I’m not sure how it would effect other results. I wonder if wp_query internally tries to make a conversion if the ‘type’ parameter isn’t set.
Maybe within the for loop you could try something like
if ( is_numeric( $v[‘value’] ) && floor( $v[‘value’] ) {
$numeric_type = ‘decimal’;
$numeric_val = settype($v[‘value’], ‘float’);
}
and then set the values below. Anyways I’ll try to play around some more this weekend.
Thanks again!
Plugin Author
TC.K
(@wp_dummy)
Sorry @lifeinthegrid,
I just found out I was edited the wrong line of code in the plugin.
Now you can try again with the latest version 1.0.7.
Actually it is the sql execute ‘numeric’ and ‘decimal’ slightly differently. Decimal is better search for float and integer.
If you commented out the
‘type’ =>
, the value will be treated as character, which is not an ideal format for search number value. It will become a problem when it come to big number for the searching.
Your suggestion is interesting, would consider to use it if my solution doesn’t work.
Good point! I put the ‘type’=> back in.
Unfortunately just ‘Decimal’ is not working by itself. It seems that the cast that is made in the main core wordpress file meta.php (line 816) is just putting Decimal in which doesn’t seem to query the result correctly at least in my version MySQL (5.5.27).
It looks like there has been a request for precision but it hasn’t been added yet: http://core.trac.ww.wp.xz.cn/ticket/19802
Here is what I ended up putting in and seems to work pretty good for now. I have not done much testing on the other data types yet or if the filter conflicts with other possible meta queries, maybe you’ll have a better grasp since your more intimate with the source… Anyways here is a quick solution that got me filtering for now…
add_filter(‘get_meta_sql’,’wqsf_cast_decimal_precision’);
function wqsf_cast_decimal_precision( $array ) {
$array[‘where’] = str_replace(‘DECIMAL’,’DECIMAL(25,3)’,$array[‘where’]);
return $array;
}
Plugin Author
TC.K
(@wp_dummy)
It seem it has to do with the sql version. I am using version 5.1.66 and it has no problem at all.
Thanks for pointing out this issue and the solution as well.