I wrote a function which search a list of properties by specify the number of guests. Each property have a specific number of guests, eg: 10, so if the user search as guests 5
the query should return that post, but my code wouldn't:
$guests_tax_array = array(
'taxonomy' => 'property-guests',
'field' => 'term_id',
'terms' => array($guests), //Searched value from $_POST['guests']
'compare' => 'IN'
);
Essentially, the query should check if 5
(searched value) is contained in 10
using the compare
operator.
But the result is empty, is something wrong there?
'compare' => 'IN'
actually means, "see if this exact value is contained in the field." So, 5 will never be "in" 10. I don't think a WP tax query actually supports checking whether a numeric value is "less than or equal to" a number, which is what you're looking for.property-guests
. So for example, maybe you have properties with room for 4, 7, and 10 guests. If a visitor searches for 5, you first get all theproperty-guests
numbers and isolate the ones that are greater than or equal to 5 (the search). Add those all to an array (at this point, an array including 7 and 10). Then, pass that array interms
in your query and you will find all the properties that have room for that many guests.