virtualgadjo Posted July 15, 2022 Share Posted July 15, 2022 Hi, i confess, i have very baaaad habits and being a db freak doens't help getting rid of them but i try hard, i swear ? so, i'm working on a website with around 60, say, debates there are around 200 speakers in each debate template there is a field (deb_inter) to assign its speakers, more often several than one then, as you can guess, the field is a multiple page reference field, so far, full pw ? now, on each speaker page i need to display the debate(s) he/she is assigned to and if i try something like this $pages->find('template=adebate, deb_inter*=' . $page->id); guess, i get an error saying that *= is not implemented for fieldtypepage, i knew it but i couldn't help trying once more... ? i've searched the docs once more (i think, i'll end knowing them by heart :)), searched the forum too but couldn't find a simple and pw way to do this, well say as simple as this $qi = $database->query("select pages_id from field_deb_inters where data = $page->id"); which does exactly what i'm looking for (even if returning only pages id instead of a pw array), baaad habits, told you ? but, as i'd like to die a little less dumb every day, i'm wondering, is there a more pw way to do this kind of selection with pw selectors and for any kind of field containing a pw array instead of a string/number thanks in advance for your ideas helping an old guy getting a little less dumb ? have a nice day Link to comment Share on other sites More sharing options...
Robin S Posted July 15, 2022 Share Posted July 15, 2022 You just need a plain equals sign. $pages->find("template=adebate, deb_inter=$page->id"); And usually I just use $page alone because the string value of a Page object is its ID. $pages->find("template=adebate, deb_inter=$page"); 4 Link to comment Share on other sites More sharing options...
virtualgadjo Posted July 15, 2022 Author Share Posted July 15, 2022 Hi @Robin S and thanks a lot for taking time to read my silly prose ? unfortunately, this doesn't work, probably becaouse it is a multiple page field type and containing an array even if only one element a foreach later, my query return Array ( [0] => 1071 ) // the page of the debate this guy is assigned to your solution (using $page as well as $page->id) returns ProcessWire\PageArray Object ( [count] => 0 [items] => Array ( ) [selectors] => template=adebate, deb_inters=1076 ) thanks again for your help ? have a nice day Link to comment Share on other sites More sharing options...
Robin S Posted July 15, 2022 Share Posted July 15, 2022 7 minutes ago, virtualgadjo said: unfortunately, this doesn't work, probably becaouse it is a multiple page field type and containing an array even if only one element Maybe it's not intuitive but an equals sign matches pages in a Page Reference field regardless of whether it is a "single page" field or a "multiple pages" field with more than one page selected in it. So it must be some other issue, like maybe your page you are trying to find is unpublished or hidden? 1 Link to comment Share on other sites More sharing options...
virtualgadjo Posted July 15, 2022 Author Share Posted July 15, 2022 @Robin S no i checked, this of course before my test choosing a published speaker assigned to a published debate (both not hidden of course too) but thanks for the info, as you say, this is not intuitive and is probably going to help me for other kind of selections within the debates (which day, days are in a select, main theme, and so on) and i have a lot to come... even less intuitive when printing the deb_inters field this should be searching through print_r($pages->get(1071)->deb_inters); // returns ProcessWire\PageArray Object ( [count] => 2 [items] => Array ( [Page:0] => Array ( [id] => 1076 [name] =>.....), [Page:1] => Array ( [id] => 1156 [name] =>...) // i spare you the full result which is quite a thing and you know that better than me :) thanks again for your help and letting me know something new for me! have a nice day Link to comment Share on other sites More sharing options...
virtualgadjo Posted July 15, 2022 Author Share Posted July 15, 2022 @Robin S actually, looking at what i've just posted, what i'm looking for would look like a selector that could be deb_inters.items*=$page in an array way but i can't find this kind of selector in the docs list ? have a nice day Link to comment Share on other sites More sharing options...
dotnetic Posted July 15, 2022 Share Posted July 15, 2022 I think you could use just $page->references('template=adebate') to get the debates that reference this speaker. See the blog post ProcessWire 3.0.107 core updates 3 Link to comment Share on other sites More sharing options...
virtualgadjo Posted July 16, 2022 Author Share Posted July 16, 2022 hi @dotnetic wow, this is huge and exactly what i was looking for and it return our beloved pw pages array instead of just ids like my query did, one bad habit less! ? you've just proved one thing, now i need to know the blog by heart too... thank you so much for your help have a nice day P.S. as i love reading articles i agree with ? the first link in your signature has changed, it's now https://dotnetic.de/blog/processwire-the-best-cms the current one throws a 404 ? 1 Link to comment Share on other sites More sharing options...
Pixrael Posted July 16, 2022 Share Posted July 16, 2022 @virtualgadjo check this, it may also be useful in your project: https://processwire.com/modules/connect-page-fields/ 2 Link to comment Share on other sites More sharing options...
virtualgadjo Posted July 17, 2022 Author Share Posted July 17, 2022 Hi @Pixrael i didn't know this module and it could be a solution actually for a lot of projects i work on as this both way relation between pages occurs very often having me write tricky php things that it could solve "natively" even if pw itself already makes things so simpler and faster! thanks a lot for your help have a nice day 1 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