I have a product attribute which is configured to be a dropdown with a fixed list of available values.

Now I need to write a script which will filter based on the selected value of the dropdown attribute. The filter needs to know the integer ID of the value, but the script input uses the text based label of the attribute.

How would I lookup the integer ID of the desired attribute value?

  • I don't understand the question. Selects in magento are normally like this: <option value="INT_VALUE">STORE_SPECIFIC_TEXT_VALUE</option> Apr 2, 2014 at 21:10

2 Answers 2


You can use something like this.

 $attribute = Mage::getModel('eav/config')->getAttribute('catalog_product', "your attribute_code");
 $arg_value = "your  text based label";
    foreach ( $attribute->getSource()->getAllOptions(true, true) as $option )

        if($arg_value == $option['label'])

            echo $option['value'] ; 

This will give you Integer ID of your text based label

  • Perfect, that's exactly what I was after
    – STW
    Apr 3, 2014 at 17:26
  • Sorry, this makes no sense for me: if($arg_value == $option['label']) Because: You try to get the current label and say if(value1 == value1value2value...) So the "if" is senseless How do I get the current ID of a current Dropdown value?
    – TonkBerlin
    Jan 5, 2015 at 17:43
  • The == operator is a comparison operator in PHP, it is not an assignment operator (which is a single = character). Given that information it should be clear that the if is not sensless at all.
    – Vinai
    Jan 7, 2015 at 20:15

Here's a more concise approach to translating a text label into it's value of:

// Returns the value ID of the 'example' label for 'some_attribute'

Bonus: To convert an integer value to a text label is a little easier:


Both of those examples leverage the catalog/product model without actually loading a product. If you're working with a loaded product you can use that instance as well.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.