How to get entity id by SKU and ATTRIBUTE ID in magento 2
I don't understand why are you fetching a product id by filtering with SKU and is_old attribute. Because SKU is already an unique value.
I am posting my answer here with two different cases.
Case 1: Get product Id using sku.
<?php
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$productId = $objectManager->get('Magento\Catalog\Model\Product')->getIdBySku('your_sku');
print_r($productId);
?>
Case 2: Get old products using sku.
<?php
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$products = $objectManager->get('Magento\Catalog\Model\Product')
->getCollection()
->addAttributeToFilter('is_old',1)
->addAttributeToFilter('sku',array('sku1','sku2',.....));
echo "<pre>";
print_r($products->getData());
?>
Instead of calling direct query, my suggestion is to get Magento collection by using product collection factory class:
Magento\Catalog\Model\ResourceModel\Product\CollectionFactory
Then filter that collection via addAttributeTofilter
<?php
namespace [YourClassNameSpace];
class [ClasssName]
{
protected $_productCollectionFactory;
public function __construct(
....
\Magento\Catalog\Model\ResourceModel\Product\CollectionFactory $productCollectionFactory,
...
) {
$this->_productCollectionFactory = $productCollectionFactory;
.....
}
public function getProductCollection(){
$collection = $this->_productCollectionFactory->create();
// Assume tghat yes/no attribute code
$collection->addAttributeToFilter('Is Old_ATTRIBUTE_CODE',1); //Use 1 for yes value
/* Filter collection by multiple sk */
$collection->addAttributeToFilter('sku',array('Sku1','sku2'.....,'sku2'));
}
}