Forum

Thread tagged as: Question, Blog

Randomly selecting blog posts from the last month

Hi Drew

Is it possible with perch_blog_custom to randomly select say 3 posts from the last month or two months?

Its the last part that I'm struggling with; I'm randonly selecting the 3 posts OK, I'm just not sure how to restrict it to those made in the last month or those that are not older than a specified number of days?

Nick Loat

Nick Loat 0 points

  • 5 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

Yes, use a filter to set the date range.

'filter' => 'postDateTime',
'match' => 'gte',
'value' => date('Y-m-d H:i:s', strtotime('- 3 MONTHS')),

Brilliant! As ever many thanks for the quick response.