Josh Pennington
Josh Pennington

Reputation: 6428

How to add "Order By" when loading a Magento Model

I am trying to load a list of items from a Magento model. What I want to do is get the items in order by their created date so that I have the newest first.

Anyone know how I can do that?

Here is what I have so far:

$model = Mage::getModel('testimonials/testimonials')
  ->getCollection();

Upvotes: 9

Views: 18944

Answers (2)

mivec
mivec

Reputation: 327

another method that can work too:

$model = Mage::getModel('package/module');

$model->getCollection()
      ->getSelect()->order();

Upvotes: 1

Josh Pennington
Josh Pennington

Reputation: 6428

I was able to find the answer on my own. This is what I had to do:

$model = Mage::getModel('testimonials/testimonials')
->getCollection()
->setOrder('created_time', 'DESC');

Upvotes: 23

Related Questions