Jump to content

Repeater field filter questions


janlonden
 Share

Recommended Posts

Here's a couple of problems I need help with.

I have a schedule page with a repeater field which has besides other fields a date field. Right now it displays all items. What I would like it to do is to only show future items and todays item.

The code I'm using:

<?php foreach($page->schedule as $schedule_item) { ?>
	<p><?=$schedule_item->schedule_date?></p>
	<p><?=$schedule_item->location->title?></p>
<?php if($schedule_item->location->location_url) { ?>
	<p><a href="<?=$schedule_item->location->location_url?>">Karta</a></p>
<?php } ?>
	<p><?=$schedule_item->starts?></p>
	<p><?=$schedule_item->ends?></p>
<?php } ?>

I would also like a "next schedule item" thingy on the homepage, which would only show the next item on the schedule or todays schedule.

Any help appreciated!

Edit:

I found help on a couple of threads here :)

Here's how I got it working. Show only future items and todays item:

<?php
$today = strtotime(date("Y-m-d") . " 00:00:00");
foreach($schedule_items = $page->schedule->find("schedule_date>=$today") as $schedule_item) { ?>

To show only one item on the homepage I just added limit=1:

<?php
$today = strtotime(date("Y-m-d") . " 00:00:00");
foreach($schedule_items = $pages->get(1007)->schedule->find("limit=1, schedule_date>=$today") as $schedule_item) { ?>
Link to comment
Share on other sites

Have you read the pages on repeaters, especially the section on: "Finding pages by repeater value (using selectors)"

You should be able to figure it out from there using a selector that finds items with schedule_date > time()

Let us know if that gets you on your way, or if you need more specific help.

  • Like 2
Link to comment
Share on other sites

I see you found your solution, but I will post mine anyway, maybe it will be of some help too ;)

<?php
$today = strtotime('today midnight');
//or if you want to show only events in future
//$today = date();
$schedule = $page->schedule->find("schedule_date>$today");
//then put $schedule in your loop  

Also you can request one item like this:

<?php
$schedule_item = $pages->get(1007)->schedule->get("schedule_date>=$today");
//maybe you'll want to sort them if they are not in the right order, then add sort=schedule_date to your selector

  • Like 2
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...