lenoir Posted May 5, 2022 Posted May 5, 2022 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?
MarkE Posted May 5, 2022 Posted May 5, 2022 2 hours ago, lenoir said: $page->repeater_agenda Is repeater_agenda your field name? It looks more like the template name.
lenoir Posted May 5, 2022 Author Posted May 5, 2022 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".
MarkE Posted May 5, 2022 Posted May 5, 2022 @lenoir I would expect the field name to be 'agenda' and for 'repeater_agenda' to be the name of the (system) template it uses.
lenoir Posted May 5, 2022 Author Posted May 5, 2022 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?
MarkE Posted May 5, 2022 Posted May 5, 2022 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.
lenoir Posted May 5, 2022 Author Posted May 5, 2022 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.
MarkE Posted May 5, 2022 Posted May 5, 2022 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).
lenoir Posted May 5, 2022 Author Posted May 5, 2022 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 ?
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now