[wp-hackers] Please Help: How to compare 2 float values in meta_value column?
Adriaan Pelzer
adriaan.pelzer at gmail.com
Wed Feb 3 14:58:50 UTC 2010
I see - I'm not even sure how you're going to do both comparisons (floor &
ceiling values) using the query_posts parameters.
What I normally do:
I do a broader query, without paging, for instance:
query_posts("category_name=$forwho&meta_value=$brand&posts_per_page=-1);
Then, in the loop, I do all the tests I need to do, and decide there if I
display the post or not.
To introduce paging, I then pass a $_GET variable around:
So, above becomes:
query_posts("category_name=$forwho&meta_value=$brand&posts_per_page=$posts_per_page&offset=$_GET['post_offset']);
Then, to link to fwd and backward pages, I generate the following links:
$page_url."?post_offset=".($_GET['post_offset']+$posts_per_page)
$page_url."?post_offset=".($_GET['post_offset']-$posts_per_page)
I display fwdlink only if the offset is smaller than the total number of
posts, and I display backlink only if its offset is greater or equal to 0.
Sorry - I know this is a bit of a tangent, but being more familiar with php
than with wordpress' functions, I tend to do things in a more "raw" way. I
hope it's useful at all.
Adriaan Pelzer
PIT Productions
+2712 651 2432
On Wed, Feb 3, 2010 at 4:30 PM, babyboy808 <hi at eirestudio.net> wrote:
>
> Thanks for the reply (and others).
>
> Unfortunetly that won't work as my problem is a little more complex.
>
> Below is a piece of my code:
>
> <?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; ?>
> <?php
>
> query_posts("category_name=$forwho&meta_value=$brand&paged=$paged&meta_compare=<=&meta_value=54");
> ?>
>
>
> Adriaan Pelzer wrote:
> >
> > Convert the meta_key strings to floats with a cast. Something like this:
> > $price = (float) get_post_meta ($post->ID, "price", TRUE);
> >
> > The value of price is now a float, and can be compared to your limits:
> > if (($price > 23) && ($price < 41)) {
> > ...
> > }
> >
> > Adriaan Pelzer
> > PIT Productions
> > +2712 651 2432
> >
> >
> > On Wed, Feb 3, 2010 at 3:02 PM, babyboy808 <hi at eirestudio.net> 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
> >> --
> >> View this message in context:
> >>
> http://old.nabble.com/Please-Help%3A-How-to-compare-2-float-values-in-meta_value-column--tp27435706p27435706.html
> >> Sent from the Wordpress Hackers mailing list archive at Nabble.com.
> >> _______________________________________________
> >> wp-hackers mailing list
> >> wp-hackers at lists.automattic.com
> >> http://lists.automattic.com/mailman/listinfo/wp-hackers
> >>
> > _______________________________________________
> > wp-hackers mailing list
> > wp-hackers at lists.automattic.com
> > http://lists.automattic.com/mailman/listinfo/wp-hackers
> >
> >
>
> --
> View this message in context:
> http://old.nabble.com/Please-Help%3A-How-to-compare-2-float-values-in-meta_value-column--tp27435706p27437166.html
> Sent from the Wordpress Hackers mailing list archive at Nabble.com.
>
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>
More information about the wp-hackers
mailing list