I need to get product collection by category id and color attribute. But It's not working.
Here is my code:
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$categoryFactory = $objectManager->get('\Magento\Catalog\Model\CategoryFactory');
$category = $categoryFactory->create()->load($cat_ids);
$categoryProducts = $category->getProductCollection();
$categoryProducts->addAttributeToSelect('*')->addAttributeToSort('position', 'ASC');
$categoryProducts->addAttributeToFilter('color', array('in',29));
Here my Sql query:
SELECT 1 AS `status`, `e`.`entity_id`, `e`.`attribute_set_id`, `e`.`type_id`, `e`.`created_at`, `e`.`updated_at`, `e`.`sku`, `cat_index`.`position` AS `cat_index_position`, `e`.`entity_id`, `e`.`attribute_set_id`, `e`.`type_id`, `e`.`area`, `e`.`cost`, `e`.`created_at`, `e`.`description`, `e`.`gift_message_available`, `e`.`has_options`, `e`.`image`, `e`.`image_label`, `e`.`is_facebook`, `e`.`is_facebook_value`, `e`.`links_exist`, `e`.`links_purchased_separately`, `e`.`links_title`, `e`.`msrp`, `e`.`msrp_display_actual_price_type`, `e`.`name`, `e`.`news_from_date`, `e`.`news_to_date`, `e`.`price`, `e`.`price_type`, `e`.`price_view`, `e`.`product_brand`, `e`.`product_items`, `e`.`required_options`, `e`.`select_delivery_time`, `e`.`select_delivery_time_value`, `e`.`select_price_label`, `e`.`select_price_label_value`, `e`.`select_units`, `e`.`select_units_value`, `e`.`short_description`, `e`.`sku`, `e`.`sku_type`, `e`.`small_image`, `e`.`small_image_label`, `e`.`special_from_date`, `e`.`special_price`, `e`.`special_to_date`, `e`.`swatch_image`, `e`.`tax_class_id`, `e`.`thumbnail`, `e`.`thumbnail_label`, `e`.`ts_dimensions_height`, `e`.`ts_dimensions_length`, `e`.`ts_dimensions_width`, `e`.`updated_at`, `e`.`url_key`, `e`.`url_path`, `e`.`visibility`, `e`.`weight`, `e`.`weight_type` FROM `catalog_product_flat_1` AS `e` INNER JOIN `catalog_category_product_index_store1` AS `cat_index` ON cat_index.product_id=e.entity_id AND cat_index.store_id=1 AND cat_index.category_id='12' ORDER BY `cat_index_position` ASC, `cat_index`.`position` ASC