0

I have created a widget that has a dropdown with the 3 choices, Sale, Rent or Both, there is a WP loop to display the results, if Sale or Rent is chosen the query works fine, but if Both is chosen it shows no results.

$sale_or_rent = $instance['feat_prop_sale_or_rent'];
if ( $sale_or_rent == 'Both' ) {
    $sale_or_rent = 'Sale,Rent';
}

Loop criteria

array (
  'key'     => 'sale_or_rent',
  'compare' => '=',
  'value'       => $sale_or_rent,
),

Can I use the $sale_or_rent in the way that I have in the criteria to denote I want both Sale and Rent to displayed, or where have I gone wrong, if I type in 'sale','rent' then I only get the first one e.g. sale how can I add both so it is Sale or Rent to display.

1

You need an IN comparison and array if you want to match multiple values.

array (
  'key'     => 'sale_or_rent',
  'compare' => 'IN',
  'value'   => array('Sale', 'Rent'),
),

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.