How to get all existing values of a specific attribute in magento


Posted on 02 Jun 15 by Vickey

In a project i had a custom attribute name as "company" and i need to add a filter on my search page so that i can filter my products by company name so i fetch all existing values used for "company" attribute by using these value i created a dropdown to show all values

here is example

$attributename= 'company';
$get_product_attributes = Mage::getResourceModel('catalog/product_collection')
            ->addAttributeToFilter($attributename, array('notnull' => true))
            ->addAttributeToFilter($attributename, array('neq' => ''))
$companyList = array_unique($get_product_attributes->getColumnValues($attributename));

in $companyList variable i got all values saved as company name

If this post help you reduce time to develop, you can help me to maintain this website :)