Select attribute - allow multiple options to be chosen *PHP HELP*

Permalink
Hi guys,

Just wondered if anyone could help me with a bit of PHP.

I'm using a page list to show certain case studies based on a select attribute called 'feature_type'. This works perfect currently using the following code (so if a case study has the select value of 'commercial' it will show up):

<?php
        $ak = CollectionAttributeKey::getByHandle('feature_type');
   $value = $page->getCollectionAttributeValue('feature_type');
   if( $value == 'commercial'){ ?>
      <!-- page list content goes here -->
<?php }?>


The client has now requested that a case study may have two values, so i've set the option in the attribute settings to 'Allow multiple options to be chosen.' But I just can't figure out how to modify the above php to reflect this, so it needs to pretty much say if any of the values equal commercial then show it. Could anyone give me a hand to figure out the code for this?

Thanks in advance!

 
Juha replied on at Permalink Best Answer Reply
Juha
Like this, for example:
<?php
  $values = $page->getCollectionAttributeValue('feature_type');
  $commercial = false;
  foreach ( $values as $value ) {
     if ( $value == 'commercial' ) {
       $commercial = true;
       break;
    }
  }
  if( $commercial == true ){ ?>
  <!-- page list content goes here -->
<?php }?>
OliR replied on at Permalink Reply
Ahh thanks very much for that, works perfectly!!!