Forum

Thread tagged as: Question, Problem

Filter by today

Hi,

I'm trying to show today's radio show via content custom on the home page. Because There are future shows in the admin, the code I'm using shows the latest show:

<?php perch_content_custom('Listen', array(
        'page'=>'/listen/listen.php',
        'template'=>'_home_listen.html',
        'sort'=>'date',
        'sort-order'=>'DESC',
        'count'=>1,
        )
    ); ?>

I've tried adding 'match':

<?php perch_content_custom('Listen', array(
        'page'=>'/listen/listen.php',
        'template'=>'_home_listen.html',
        'filter' => 'date', 
        'match' => 'between', 
        'value' => "$today, $past_date",
        'sort'=>'date',
        'sort-order'=>'DESC',
        'count'=>1,
        )
    ); ?>

But that does display anything. Do I need to add anything to the master template re 'today' or is the above wrong?

Thanks!

Elliot Wilsher

Elliot Wilsher 0 points

  • 3 years ago

That's because you are trying to use variables in a string

should be

'value' => $today.", ".$past_date,

Have you set your today and past_date variables?

Thanks Dexter.

Do I need to set today and past_date in the master template?? If so, probably not ... I've not tried to exclude future items before.

Drew McLellan

Drew McLellan 2638 points
Perch Support

This is fine, as the variables will be interpolated.

'value' => "$today, $past_date",

But where are those two variables defined?

Thanks Drew.

I'm not sure they are defined anywhere. I think I was hoping 'today' would always be 'today'. Each show has a date but the client wants to load up a few weeks shows in advance, but have "today's" show appear on the home page.

Hope that makes sense ... currently my code displays the show with the last show added to the db.

Elliot

Drew McLellan

Drew McLellan 2638 points
Perch Support

Today would be, for example:

$today = date('Y-m-d H:i:00');

Right, thanks. This is new to me, but this seems to work:

Seem ok to you Drew?

<?php 
      $today = date('Y-m-d H:i:00');
      perch_content_custom('Listen', array(
        'page'=>'/listen/listen.php',
        'template'=>'_home_listen.html',
        'filter' => 'date',  
        'match' => 'lte', 
        'value' => "$today",
        'sort'=>'date',
        'sort-order'=>'DESC',
        'count'=>1,
        )
    ); ?>
Drew McLellan

Drew McLellan 2638 points
Perch Support

If it's doing what you want then it's fine.

Just removed 'sort' and 'sort-order' as un-needed with count set to 1 :)

Thanks Drew!