How can i get latest products programmatically in magento 2?


try this

$productCollectionFactory = $objectManager->get('\Magento\Catalog\Model\ResourceModel\Product\CollectionFactory');
$collection = $productCollectionFactory->create();
$collection->setPageSize(5); // selecting only 5 products

foreach ($collection as $product) {
    echo "<br>";
  • Thankyou the code is working fine.... – srg Aug 4 '17 at 9:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.