Support » Plugin: WP Query Search Filter » Support for Double and Floating Point Values

  • First off very nice plugin! Looks like it has quite a bit of potential, definitely a 5 star. I was currently testing against some meta values that have floating point numbers and it doesn’t seem to read correctly.

    If I setup my meta-key as such:
    >= (greater equal to) with the options “1|2.0|2.5|3|4” it seems to filter fine for the non-floating point numbers but anything that has the decimal doesn’t seem to filter.

    For example if I choose 2.5 from the options it won’t include keys in the table with 2.5 but it will include 3 and greater. Is this something that is supported?

    Thanks in advance…

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author TC.K


    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



    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


    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:

    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…

    function wqsf_cast_decimal_precision( $array ) {
    $array[‘where’] = str_replace(‘DECIMAL’,’DECIMAL(25,3)’,$array[‘where’]);
    return $array;

    Plugin Author TC.K


    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.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Support for Double and Floating Point Values’ is closed to new replies.