Jump to content

Last and first selectors (in repeaters) ?


Recommended Posts

The repeater is basically a PageArray. So you can use the normal Page/WireArray methods.



Look at the Cheatsheet under Page/WireArray. Hope this helps.

Sorry read it to fast.

But it's a PageArray and regarding to the documentation this might work:

$myRepeater->last()->find("myRepeater.fieldname != '' ").

Hopefully someone else can help.

Link to comment
Share on other sites

Don't understand the question exactly, but here are some nice docs: http://processwire.com/api/fieldtypes/repeaters/

Also repeater pages have a special template called "repeater_yourField". So theoretically you could also get repeater pages the following way:

// Get last item sorted by created DESC
$item = $pages->find("template=repeater_yourField,sort=-created,limit=1"); 

// Get first item sorted by created with an additional condition 
$item = $pages->find("template=repeater_yourField,sort=created,field|field2%=blub,limit=1"); 
  • Like 3
Link to comment
Share on other sites

  • 3 years later...
3 hours ago, Can said:

would love that too, could use it on a table field to know while searching if the first/last entry matches

It requires a couple of steps, but so long as your pages selector doesn't return a huge number of results this should be fairly low impact:

$value = 'Foo';
$all_matches = $pages->find("my_table.my_field=$value");
$first_row_matches = $pages->newPageArray();
foreach($all_matches as $match) {
    if($match->my_table->first()->my_field == $value) $first_row_matches->add($match);


  • Like 1
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

  • Create New...