Jump to content

bad habits into pw syntax


virtualgadjo
 Share

Recommended Posts

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

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

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.

2022-07-15_204947.png.d80365e56f23f73d69a8c2209420042d.png

So it must be some other issue, like maybe your page you are trying to find is unpublished or hidden?

  • Like 1
Link to comment
Share on other sites

@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

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 ?

  • Like 1
Link to comment
Share on other sites

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

 

 

  • 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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...