3

I am new in Craft CMS and this is my first plugin. Below is my code to get products.

{% craft.entries.section('products').limit(9) %}

This code is working fine but can I use this code in my controller for getting products?

Thanks

1 Answer 1

4

If you want to use ElementCriteria in your controller, this is how to go about it:

$criteria = craft()->elements->getCriteria(ElementType::Entry);
$criteria->section('products');
$criteria->limit = 9;

$products = $criteria->find();

Read this page for more info on the subject.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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