We use this Magento code to get a list of publications to pick 2 from to show in a Bookstore section.
$collection = Mage::getModel('catalog/category')->getCollection();
$collection->addAttributeToSelect('url_key')
->addAttributeToSelect('name')
->addAttributeToSelect('id')
->addAttributeToSelect('description')
->addAttributeToSelect('is_anchor')
->addAttributeToFilter('is_active', 1)
->joinUrlRewrite()
->load();
How can I add an attribute to select to make it not include the publications that are set
to “Not show individually”?
If I add this:
->addAttributeToFilter('visibility', 4) // Only catalog, search visiblity
The code fails with message ‘Invalid attribute name: visiblity’
Visibility is a product attribute, not a category attribute. To get products that only have a visibility of 4, you need to get a product collection and traverse over it to get a definitive list of categories:
Now, with the
$categoriesarray populated with our unique list of categories, we can load only those categories: