Joe Barrett Joe Barrett - 2 months ago 8
PHP Question

I can't figure out php syntax

I have taxonomies that i need called here,

if ( $the_tax->name == 'day' , 'drink_type') {
$tax_output = '';
}
return $tax_output;
}


The above code is written wrong, The taxonomy of day works, i can not figure out how to ref a second taxonomy of drink_type.
do i use a comma? or || or what () if anyone knows php syntax and can help THANKS!

Answer

You either need logical OR (which can be written as || (common syntax) or just OR (which is PHP specific so I rather do not recommend using) - see logical operators doc for more details. So your code should look like this:

if( ($the_tax->name == 'day') || ($the_tax->name == 'drink_type') ) {
   // at least one condition met
}

or use in_array() if you going to have more allowed names:

$names = ['day','drink_type'];
if( in_array($the_tax->name, $names) {
  // allowed name...
}