Jump to content

Accessing fields in Repeater outside of page?


V7dev
 Share

Recommended Posts

I can't find anything specific in my searches, so I figured I would ask for some guidance!

So I have a repeater field that I'm trying to search for outside a page. Here's my structure:

  • Home
    • Events (events template)
      • Event (event template)
        • Part One (event_day template)
          • Repeater (named event_schedule)
            • Event Start Date (event_start_date)
            • etc...
        • Part Two
        • etc...
    • Speakers (speakers template)

So from the speakers template I'm trying to access the repeater with the following:

$pages->find("template=event_day, event_schedule.speakers={$page->id}");

How do I access the actual fields inside the repeater, for example, the above dumps the following, which is correct, just can't access the event_start_date field?

image.thumb.png.75937aa87d24f404b9fcacb85b197e90.png

Let me know if there's more info needed. Thank you!

Link to comment
Share on other sites

@V7dev you just need a loop

$items = $pages->find("template=event_day, event_schedule.speakers={$page->id}");

foreach($items as $item) {
	foreach($item->event_schedule as $repeater_item) {
		echo $repeater_item->event_start_date;
	}
}

 

  • Like 1
Link to comment
Share on other sites

19 minutes ago, ngrmm said:

@V7dev you just need a loop

$items = $pages->find("template=event_day, event_schedule.speakers={$page->id}");

foreach($items as $item) {
	foreach($item->event_schedule as $repeater_item) {
		echo $repeater_item->event_start_date;
	}
}

 

So that's what I was missing, thanks so much!

  • Like 1
Link to comment
Share on other sites

@V7dev in case you wonder, why you do not see the repater in you dump. Repeaters are pages themself linked to your actual page

Also see here for more options to get the repeater items:

 

Link to comment
Share on other sites

$items = $pages->find("template=event_day, event_schedule.speakers={$page->id}");

foreach($items as $item) {
	foreach($item->event_schedule as $repeater_item) {
		echo $repeater_item->event_title . '<br>';
	}
}

It will echo out all the repeaters for that page, even though the speaker is only in one of them? What's the point of the first portion ($items) if you have to make another exception to see if the speaker is in the second foreach loop?Apologies for perhaps not seeing the forest from the trees!

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...