0

if I make the query of

        $apartments = get_posts( array ( 'post_type' => 'apartment','meta_key' => 'bedrooms','meta_value'=> array(4,12) , 'compare' => 'BETWEEN' , 'type' => 'NUMERIC'));

I only get 4 and 8 bedroom apartments.

if I make the query of

        $apartments = get_posts( array ( 'post_type' => 'apartment','meta_key' => 'bedrooms','meta_value'=> array(4,5,6,7,8,9,10,11,12) , 'compare' => 'IN' , 'type' => 'NUMERIC'));

I also get 7 bedroom ones...

Why is the top item not seeing the 7 bedroom apartments? Am I not using BETWEEN properly?

Thanks

0

As you are looking at post IDs, you should be using meta_value_num instead of meta_value as your key. This will indicate to WP how to handle the comparison.

  • Wow, silly me - I thought 'type' => 'NUMERIC' would be telling WP how to handle the comparison. I will test and respond with findings soon. Thanks for your time @vancoder. – johnlewisdesign Aug 12 '15 at 11:40
  • OK...so now that brings back everything between 4 and 12 - thanks @vancoder that's great! New issue imminent :) – johnlewisdesign Aug 12 '15 at 12:57
  • No problem. You should start a new issue as a new post, and feel free to mark my answer correct. – vancoder Aug 12 '15 at 19:01
  • Thanks, I was going to create a new post but can work around it anyway thanks to this piece of valuable info :) – johnlewisdesign Aug 14 '15 at 15:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.