Jump to content

Sort repeater by datetime field


lenoir
 Share

Recommended Posts

Hi,

this seemed quite straight forward, still can't get my head around it…

I have a repeater with 2 fields (title and datetime). I want to sort the repeater items in the API by the datetime field. But it doesn't work. 

foreach($page->repeater_agenda->sort("eventdate") as $agenda){

}

This doesn't do anything. Am I missing something?

Link to comment
Share on other sites

1 minute ago, MarkE said:

Is repeater_agenda your field name? It looks more like the template name.

yes, my repeater is called "repeater_agenda" and has 2 fields, title and a datetime called "eventdate". 

Link to comment
Share on other sites

4 minutes ago, MarkE said:

@lenoir I would expect the field name to be 'agenda' and for 'repeater_agenda' to be the name of the (system) template it uses.

I don't get your point, sorry. I don't see what this has to do with my issue?

Link to comment
Share on other sites

1 minute ago, lenoir said:

I don't get your point, sorry. I don't see what this has to do with my issue?

When you create a repeater field, say 'fieldname', PW automatically creates a template called 'repeater_fieldname'. It looks like you are using this, not the actual field name. If you actually called your field 'repeater_agenda' then the template will be called 'repeater_repeater_agenda' (check your templates list with system templates filter turned on). I wanted to eliminate the possibility that you might be calling the template rather than the field.

Link to comment
Share on other sites

Just now, MarkE said:

When you create a repeater field, say 'fieldname', PW automatically creates a template called 'repeater_fieldname'. It looks like you are using this, not the actual field name. If you actually called your field 'repeater_agenda' then the template will be called 'repeater_repeater_agenda' (check your templates list with system templates filter turned on). I wanted to eliminate the possibility that you might be calling the template rather than the field.

Oh I didn't know this. I actually started calling all my repeaters "repeater_…" but that might not be the brightest idea in that case. But I find sometimes forget which fields are repeaters and which aren't, that's why I started doing this.

But I guess this isn't the problem, since I'm pointing to the right field.

Link to comment
Share on other sites

7 minutes ago, lenoir said:

But I guess this isn't the problem, since I'm pointing to the right field.

Hmm. I can't see anything wrong with the code you quoted. Do you have Tracy Debug installed (if not then I really recommend it). If so, try your code in the console (when you are on the page in question).

Link to comment
Share on other sites

Ok, I wrote the php codes from scratch and now it works. Very strange. Definitely a mistake from my part. 

Thanks for suggesting Tracy Debug, I'm testing it right now ?

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