Clarity Posted July 27, 2022 Share Posted July 27, 2022 Hello everyone! I need to access first element of Page Reference (and generally first element of any collection) field using a selector. Something like $pages->find('page_reference.first=value'). I can't find how to do it in the documentation. Can you please advice me how to do it? Link to comment Share on other sites More sharing options...
3fingers Posted July 27, 2022 Share Posted July 27, 2022 https://processwire.com/api/ref/wire-array/first/ 1 Link to comment Share on other sites More sharing options...
Clarity Posted July 27, 2022 Author Share Posted July 27, 2022 Thank you, but can I actually use it in the selector string? I need to find the pages with specific Page Reference and access the first element of them, not simply get the first page of the collection. Link to comment Share on other sites More sharing options...
3fingers Posted July 27, 2022 Share Posted July 27, 2022 What about: $pages->findOne('page_reference=value') Not tested but findOne method should return just the first occurence of the page array. 1 Link to comment Share on other sites More sharing options...
Clarity Posted July 27, 2022 Author Share Posted July 27, 2022 Sorry if I was unclear, but it's not quite what I want. I need all pages with this Page Reference and with given in the selector value of the first element of this Page Reference, not the first page with this Page Reference. Link to comment Share on other sites More sharing options...
bernhard Posted July 27, 2022 Share Posted July 27, 2022 I'm not sure if that is possible with a selector, but a workaround would be to add a second hidden field to your template and create a hook that populates that field on save or saveReady. Then you can simple use a selector like this: $pages->find("template=yourtemplate, your_hidden_reference_field=$yourpage"); 1 Link to comment Share on other sites More sharing options...
Clarity Posted July 27, 2022 Author Share Posted July 27, 2022 Thank you, I already found that I can use additional single-valued Page Reference for my purposes. Link to comment Share on other sites More sharing options...
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