Remove post/product from collection
addAttributeToFilter
is a method that can be called on EAV collections in Magento. 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:
$_products = Mage::getResourceModel('catalog/product_collection')
->addAttributeToSelect(array('name', 'product_url', 'small_image'))
->addAttributeToFilter('sku', array('like' => 'UX%'))
->load();
To use with Fishpig (non EAV collections), you instead need to use addFieldToFilter
, like so:
$posts = \Magento\Framework\App\ObjectManager::getInstance()->create('FishPig\WordPress\Model\ResourceModel\Post\Collection')
->addPostTypeFilter('post')
->setOrderByPostDate()
->addCategoryIdFilter(array($currentCategoryId))
->addIsViewableFilter()
->addFieldToFilter('id', array('neq' => $currentPostId))
->load(); ?>