Magento: Cant get product collection use custom attribute filter?

I have a collection of products in my magento catalog that are tagged as samplers. I need to pull back this specific collection. The attribute is part of an attribute set called candies.

When I go to load the collection, I add a filter to narrow by the attribute set, and then add another filter for the sampler attribute I created. No matter what I do with the filter, I always get back ALL the candies not just the ones with the attribute of sampler set to "yes" or 1.

Here is my code, how do I get the result I am looking for?

 $products = Mage::getModel('catalog/product')
    ->addAttributeToSelect('*')  //select all fields available to product
    ->addFieldToFilter('attribute_set_id', 9) //filter the collection by the candies attribute set
    ->addAttributeToFilter('sampler','yes'); //filter the collection to only products that have the attribute sampler set to "yes" - this part doesnt work.

Thanks in advance.

See this:

After considering the comments here, I would try this setting.

How to get product collection in Magento 2. Get product collection in Magento 2 means showing the items in your store when you run the command. With the code snippet in this topic, you can request the specific number of the product as you need.

You'll have iterate over the collection. Load the id of each product, then use ->getAttributeText('').

    $collection = Mage::getModel('catalog/product')->getCollection()
    ->addAttributeToFilter('type_id', 'configurable')
    foreach ($collection as $_product) {
        $id =  $_product->getId();
        if($tncValue = $_product->load($id)->getAttributeText('terms_and_conditions')){
            echo $id . ' => ' . $tncValue . "\n";

The best way to filter Magento products with a specific attribute set is by adding a layered navigation Magento 2 extension to your store. Such an extension will help you enhance the overall store navigation by adding advanced product filters to i

    $products = Mage::getModel('catalog/product')
        ->addFieldToFilter('attribute_set_id', 9)
        ->addAttributeToFilter('sampler', array('eq' => '1'));

I try add custom product filters. Add filter code */ class Rating extends \Magento\Catalog\Model\Layer\Filter\AbstractFilter { /** * Active Category

As of Magento 2.3.4, the filter attribute of the products query accepts the ProductAttributeFilterInput object. (In previous versions, the filter attribute required a ProductFilterInput object. This object contained a hard-coded list of filterable attributes, and you could not filter on a custom attribute or any other attribute that was not on

Sometimes one needs to have additional filtering criteria inside of a catalog’s product grid. Here is an extension that adds custom product attribute to search filter. You can choose to use any product attribute and it will be shown in the product grid. The extension settings shows up under System->Configuration menu in its separate tab.

addAttributeToFilter is a method that can be called on EAV collections in Magento 1 and Magento 2. This includes product collections, category collections, customer collections and many more. In short, it adds a condition to the WHERE part of the MySQL query used to extract a collection from the database, therefore allowing you to filter the collection by custom conditions.