Jump to content


Photo

selecting from a [multi] Page field?

solved

  • Please log in to reply
3 replies to this topic

#1 wes

wes

    Jr. Member

  • Members
  • PipPip
  • 14 posts
  • 0

  • LocationBoston, MA

Posted 27 February 2012 - 02:12 AM

Hello,

So, I have course pages and faculty pages. When I create a new course, I can associate it with 1 or more faculty members by adding them to the course_instructors Page field. When I visit the faculty member's page, I want to view the courses they teach.

I'm trying to do this with a selector:

// on the faculty member's page
$spring_courses = $pages->find('parent=/courses/spring/, course_instructors=$page');

$spring_courses is empty. Just to reiterate, course_instructors is a page field that can have multiple pages in it (multiple instructors).

I'm basing my method on this post.

Thanks for any suggestions!

#2 slkwrm

slkwrm

    Sr. Member

  • Members
  • PipPipPipPip
  • 248 posts
  • 66

Posted 27 February 2012 - 07:12 AM

Try to do this (written in browser):

$spring_courses = $pages->find('parent=/courses/spring/')->has('course_instructors=$page');


Just realized it's totally wrong. Sorry for disinformation. Please, use Soma's method.

#3 Soma

Soma

    Hero Member

  • Moderators
  • 3,186 posts
  • 1739

  • LocationSH, Switzerland

Posted 27 February 2012 - 07:34 AM

I think the "parent=" in the find does only look for direct child pages not on all levels. Not sure though if that's your problem. Apart from that it should work if you use "" instead of '' for the selector string. This is because '' won't get parsed, so using "" will work with the $page var inside.

Also not sure if slkwrm's will work in your case.( with "")

I always use the get() to go to a certain branch and do a find.

$spring_courses = $pages->get("/courses/spring/")->find("course_instructors=$page");

@somartist | modules created | support me, flattr my work flattr.com


#4 wes

wes

    Jr. Member

  • Members
  • PipPip
  • 14 posts
  • 0

  • LocationBoston, MA

Posted 27 February 2012 - 02:02 PM

I think the "parent=" in the find does only look for direct child pages not on all levels. Not sure though if that's your problem. Apart from that it should work if you use "" instead of '' for the selector string. This is because '' won't get parsed, so using "" will work with the $page var inside.

Also not sure if slkwrm's will work in your case.( with "")

I always use the get() to go to a certain branch and do a find.

$spring_courses = $pages->get("/courses/spring/")->find("course_instructors=$page");


Ohhh, good catch. Switching the quotes in fact did the trick. Your get/find method works, as well as my original method.

Thanks everyone.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users