I'm working on a filter for a wordpress page and I'm having trouble when trying to use multiple values.
The idea is to use a boolean to show or not show an item. Each item uses ACF to get various fields, in this case is color.
if( isset($colores) ){
foreach($colores as $color){
if( in_array ( $color, get_field( 'color', get_the_ID() ) ) ){//Matches the filter
$pasaColor = true;
}else if($color == null){//Not specified in the filter
$pasaColor= true;
}else{//doesn't match the filter
$pasaColor= false;
}
}
}
This works if $colores
has only one element, like this:
(
[0] => yellow
)
I compare it with the values of each item:
(
[0] => yellow
[1] => red
[2] => blue
)
This result in: $pasaColor=true
(
[1] => red
[2] => blue
)
This one results in : $pasaColor=false
But if the filter gives more than one element only the last one stays true.
Filter:
(
[0] => yellow
[1] => azul
)
Item1:
(
[0] => yellow
[1] => red
[2] => pink
)
This results in $pasaColor=false
Item2:
(
[0] => blue
[1] => red
[2] => pink
)
This results in $pasaColor=true
In item1 the result I'm getting means that the value "yellow" cannot be found in an array that actually contains the value "yellow".
And while we are at it, is there a simpler way to do this?