Jump to content

Complex PHP Selector for pagefield

Recommended Posts

I have a template called "activity" with two pagetable fields.





uses "cast" template for creating castpages.

the cast template contains a pagefield called select_multi_dates.


uses "date" template for creating datepages.

the date template contains a pagefield called select_activity.

Now what i want is create a cast with activity_create_cast and I want that the selection of the select_multi_dates pagefield should be the pages wich i created before with the activity_create_date.

How can I achieve this under the select_multi_dates pagefield with a PHP-Selector?

I know its complicated PHP-Selector. Hope you can help me.

Thanks for your attention.


Share this post

Link to post
Share on other sites

All Castpages are created under the activity:

It looks like this:


And the select_multi_dates field is on the cast template. So I thought i could get the current Activity with the casts parent and then access the items/pages from the activity_create_date pagetable.

$currentActivity = $page->parent;

return $currentActivity->activity_create_date;

Unfortunately it doesnt work, I get this error:

Fatal error: Call to a member function has() on a non-object in /Users/praktikant/Sites/Kulturdatenbank.pw.2.0/wire/modules/Inputfield/InputfieldPage/InputfieldPage.module on line 253

Share this post

Link to post
Share on other sites

I tried to echo $page on the select_multi_dates field. I get this:


$page dont return the cast page, it returns the "Fredi - edit page process" page.

How can I solve this?

Share this post

Link to post
Share on other sites

The method InputfieldPage::getSelectablePages needs to know the page you are editing. This seems to be wrong and it is probably Fredi's fault since you are getting "his" ID. Try disabling Fredi and see if it works. 

Otherwise you can try to Hook before InputfieldPage::getSelectablePages and make sure it sees the right page

$event->arguments(0, $page_you_want);

I hope this helps. 

Share this post

Link to post
Share on other sites

Thank you for your input Thomas. But it does not matter more because I have changed the concept. I'm working now with Custom Admin Pages in the Backend, creating Dashboards, Listers with ListerPro for the different Pages: Event, Dates, Images, Videos etc.... The Goal is to achieve a Culturedatabase with the Processwire-Backend where you can create/edit events, dates or also import/export the data for individual use in other websites/services. Before I have done this with a Frontend for the Backendsystem where you can create/read/update/delete events, dates with the Fredi-Module from apeisa. But still thank you for your commitment.

PS: Processwire is great :lol:

Share this post

Link to post
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

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By snck
      Hi there,
      I have a problem constructing a selector that finds all pages that refer to pages with a specific template.
      I have pages using an event template and I want to show events based on a specific context. In this example I want to filter the results and only show event pages that relate to a specific template (exhibitions) in their page field related_pages.
      What I tried:
      $events = $pages->find("template=event, related_pages.template.name=exhibition"); Unfortunately it does not work (0 results).
      Same with this:
      $events = $pages->find("template=event, related_pages=[template.name=exhibition]"); At the moment I am helping myself with the following lines, but I have a strong feeling that there is a more efficient solution:
      $events = $pages->find("template=event"); foreach($events as $event){ if(!count($event->related_pages->find("template=exhibition"))){ $events->remove($event); } }  
      I really hope that one of you can help me out.
      Thanks in advance!
    • By EyeDentify
      Hello dear PW gurus.

      I have stumbled over a strange error that i all of sudden got when trying to upload an image to a images field on a page.
      There where images allready stored in the field that i wanted to keep, but during the upload the error apear and after that all images are gone from the field and i can´t upload any, i just get the error every time.
      I am running ProcessWire 3.0.153 dev.
      After looking in the assets folder i find the folder for the page and the image files seems to be there including the ones i tried to upload when the error occured.
      But they don´t show up in the images field in the page editor.
      The error reported:
      SQLSTATE[01000]: Warning: 1265 Data truncated for column 'ratio' at row 1 And here is a screenshot of the event:

      The TracyDebugger Error reporting:

      I hope you fine folks could point me in a direction.
      But it seems our old pal set_time_limit() is back.

      Regards, EyeDentify
    • By Kiwi Chris
      The selector in the following code included in a template is returning nothing, however if I take out the compId.resultsdate<={$today} bit, it works fine, although obviously not filtered on the date field.
      $today = strtotime(date('Y-m-d')); $setImages = $pages->find("template=competitionImage, compId={$page->id}, compId.resultsdate<={$today}, compSubject.name=s, imageRating.title=Merit|Honours,check_access=0"); Here's the results of an example from Tracey Debugger
      templates_id=79, resultsdate<=1587729600, status<2048   SELECT pages.id,pages.parent_id,pages.templates_id FROM `pages` JOIN field_resultsdate AS field_resultsdate ON field_resultsdate.pages_id=pages.id AND (((field_resultsdate.data<='2020-04-25 00:00:00' ) )) WHERE (pages.templates_id=79) AND (pages.status<2048) GROUP BY pages.id Over in my ready.php I have inside a hook that refers directly to the page template that's used for the pages in the page field above:
      $today = strtotime(date('Y-m-d')) $event->return = $event->pages->find("template=competition,eventEnd>={$today},eventStart<={$today}"); In this case the filtering on date fields (albeit different ones) works fine. Can anyone suggest why the filter on the date subfield of the page field isn't working?
      Just to confirm, I do have a date value in the field, and it is a date before today. 🙂
      The problem may be something blatantly obvious, but I can't for the life of me figure out why the selector is returning no results when I include the date filter.
    • By Spyros
      I'm having a strange issue with the $page->find(), for some reason I'm missing some of the pages from the results. I found then that I was missing all the pages with the same "PAGE NAME". Is it a bug or am I missing something?
      If I change the "PAGE NAME" of one of the missing ones then I'm retrieving the page without any problem.
      Thank you
  • Create New...