1

i want to get attribute value for multi select attribute,

below is code that work if it is just text field or drop down , but for multi select it does not work , please guide way to fix it

$_product->getMetal();

works for text attibute for not for multiselect attibutes.

I am using above code on product listing page.

sample snap from where $_product comes:

<?php foreach ($_productCollection as $_product): ?>
1
  • Use this code also $_product->getData('attribute_code_here');
    – Vishal
    Commented Feb 26, 2016 at 9:18

1 Answer 1

2

This should give you what you need

$_product->getAttributeText('attribute_code_here');

If you are using this from a collection, make sure the attribute you use is marked as "Used in product listing" and that you rebuilt the indexes.

6
  • it does not give any output , metal is multiselect dropdown attribute , and using this code on product listing page
    – mcoder
    Commented Feb 26, 2016 at 9:54
  • but does $_product->getMetal() output something?
    – Marius
    Commented Feb 26, 2016 at 9:55
  • no but $_product->getPrice() and weight works fine
    – mcoder
    Commented Feb 26, 2016 at 9:59
  • in this case, it depends on the context. If $_product comes from a product collection, maybe the attribute metal is not added to the collection. You should add more info in your question. Provide the context that uses this.
    – Marius
    Commented Feb 26, 2016 at 10:00
  • 1
    added that code is used on product listing page
    – mcoder
    Commented Feb 26, 2016 at 10:03

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.