magento - sort product collection by using addAttributeToSort for custom attribute - not working

magento, php, sorting

Solution

I feel you need to work with admin also.

go to Admin->Catalog->Attributes->Manage Attributes than click on featured_product to edit it and from edit screen

set Used in Product Listing = Yes

Used for Sorting in Product Listing = Yes

and save the attribute and clear the cache.

if require than re-index the data.

Problem

I want to make the sorting via getLoadedProductCollection. For product attribute, I have one custom attribute 'featured_product' Here is my code: ``` $sort=$_GET['s']; $_productCollection=$this->getLoadedProductCollection()->addAttributeToSelect('featured_product'); $_productCollection->clear(); $_productCollection->getSelect()->reset(Zend_Db_Select::ORDER); switch($sort) { case 'lp': $_productCollection->addAttributeToSort('price', 'ASC'); break; case 'hp': $_productCollection->addAttributeToSort('price', 'DESC'); break; case 'fp': $_productCollection->addAttributeToSort('featured_product'); break; } ``` For first 2 cases, it works with no problems. But the third one is not working at all. I want to move all the featured products to the beginning of the collection list. How can I change the code for achieving the third case? Thanks

Original source