[wp-hackers] Please Help: How to compare 2 float values in meta_value column?

Michael Pretty mpretty at voceconnect.com
Wed Feb 3 13:24:13 UTC 2010

One option:

Add filters to 'posts_where' and 'posts_join' to do your own join to the 
postmeta table and where clause that compared the values cast as float.  
Then add a query_var to identify when this filter should run and what 
values to use.

Second option:

Though this won't work if you need the between operator, you could store 
the prices in the postmeta table as a string with leading zeros so that 
all values are the same width.  Then compare to '00023.00' and '00041.00'.

Michael Pretty

On 2/3/10 8:02 AM, babyboy808 wrote:
> Hi Guys,
> I have about 100 posts in wordpress, all with a meta_key of price and a
> value. How would I go about searching through all posts with a value between
> 23.00 and 41.00 for example?
> I know that 'meta_compare ' treats 'meta_value' as a string, so I can't use
> this to solve my problem.
> Anybody have any clues?
> Thanks

More information about the wp-hackers mailing list