Forum

Thread tagged as: Question

Schedule Start and End Date to post content

I have had a few requests now to be able to add a notice of of items of content and then schedule when they appear on the site, ie between 2 dates. Is this even possible as I've tried using eqbetween to achieve this but have had no success?

Richard Lowe

Richard Lowe 0 points

  • 5 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

Yes, that's possible. What code are you using, and how is it failing?

Richard Lowe

Richard Lowe 0 points
Registered Developer

I have these three items in my template

<perch:content type="checkbox" id="visibility" value="1" label="Is item visible" suppress="true"/>
<perch:content type="date" id="datestart" format="dmy" label="Date to show this item from" suppress="true"/>
<perch:content type="date" id="dateend" format="dmy" label="Date to end displaying this item" suppress="true"/>

And on my page


<?php perch_content_custom('Notices', array( 'template' => 'notice_listing.html', 'filter' => 'visibility', 'value' => 1, )); ?>

What I need to know is how to only display the item if today's date falls between or on the datestart & dateend

Richard Lowe

Richard Lowe 0 points
Registered Developer

It's OK, I worked it out I think using

<?php

$today = date('Y-m-d');

 perch_content_custom('Notices', array(
               'template' => 'notice_listing.html',
               'filter'   => 'visibility',
               'value'    => 1,
               'filter'   => 'datestart',
               'match' => 'lte',
               'value'    => $today,
               'filter'   => 'dateend',
               'match' => 'gte',
               'value'    => $today,

          )); 

?>
Drew McLellan

Drew McLellan 2638 points
Perch Support

You're actually only filtering by dateend there, as you reset the options each time you reuse them.

Instead you need to use an array of filters:

perch_content_custom('Notices', array(
     'template' => 'notice_listing.html',
     'filter'   => [
          [
               'filter' => 'visibility',
               'value'  => 1,
          ],
          [
               'filter' => 'datestart',
               'match'  => 'lte',
               'value'  => $today,
          ],
          [
               'filter' => 'dateend',
               'match'  => 'gte',
               'value'  => $today,
          ],
     ],
)); 

Richard Lowe

Richard Lowe 0 points
Registered Developer

Thanks, Perfect!