There are a few ways of doing this. Personally I would suggest listening to the event catalog_product_collection_load_before
. This can be done with the following section of config.xml
<events>
<catalog_product_collection_load_before>
<observers>
<your_module>
<type>singleton</type>
<class>your_module/observer</class>
<method>catalogProductCollectionLoadBefore</method>
</your_module>
</observers>
</catalog_product_collection_load_before>
</events>
Then in your observer you should be able to add the filters that you need with something like the following.
public function catalogProductCollectionLoadBefore(Varien_Event_Observer $observer) {
/** @var Mage_Catalog_Model_Resource_Product_Collection $collection */
$collection = $observer->getCollection();
$collection->addAttributeToFilter('attribute_code', array('in' => array(5,6)));
// If you log your select then you can double check that the correct sql is being formed
mage::log((string) $collection->getSelect());
}
Obviously you can remove the mage::log once you have the correct filters on your collection.