views:

167

answers:

1

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

+1  A: 

I would try to implement the posts_where filter, and modify the query there. It gets called right after the meta comparison is added, and it allows you to change the WHERE part of your query. You need to replace all instances of your meta key to CAST(meta_key AS DECIMAL(5,2)). I guess the meta key is prefixed by the meta table name, so check for that. You will need to figure out a way to pass two meta_value parameters if you want to do a BETWEEN query, but you can combine them with a comma and split them up in your filter. As long as a valid SQL where-clause comes out of you filter, everything should work.

Jan Fabry
I just solved this with this exact message. I love CAST!
Keith Donegan