Jump to content

using wire("pages")->find with "|" operator and multiple selectors


anowitz
 Share

Recommended Posts

I'm building my first site with PW and am absolutely loving it.  I've spent a lot of time reading the forums--fantastic community!--but can't seem to find the answer to my question....so here goes.

I'm building a website for an art gallery and would like to have a section on the "exhibitions" page called "related news and press." 

The page hierarchy looks something like this

"exhibitions-parent" (not visible)

--"picasso exhibit"

"news-parent" (not visible)

--"Picasso exhibit opens!"

--"New book about Picasso's life and times released"

"press-parent" (not visible)

--"Review of Picasso exhibit in the NYTimes"

Children of "news-parent" use the template "news," which contains two relational page fields called "news_artist" and "news_exhibition"

Children of "press-parent" use the tamplate "perss," which contains two relational page fields called "press_artist" and "press_exhibition"

In my "related news and press" section I'd like to output all news or press items that are linked to either the exhibit or the artist.

I know that the "|" can be used in selectors like this: firstname=Mike|Steve

What I'd like to do, however, is something like this:

$recent_news_and_press = wire("pages")->find("press_exhibition=$exhibition_id | news_exhibition=$exhibition_id | press_artist=$exhibition_artist | news_artist=$exhibition_artist");  

I know this is the wrong syntax, as it doesn't work.  Is there a way to do this in one find query, or do I need to run all those queries separately, and then combine them into an array?

Also, is there a risk of duplicate results when doing this sort of query, and if so does anybody have any advice on that?

Thanks so much!

Link to comment
Share on other sites

Thanks for the quick reply Adrian.  I'm trying to replicate "or."  If I understand selectors correctly, doing "press_exhibition=$exhibition_id, news_exhibition=$exhibition_id, press_artist=$exhibition_artist, news_artist=$exhibition_artist" would replicate "and" - is that right?  Is there a way to replicate "or"?
 

Link to comment
Share on other sites

Actually haven't used this myself before, but try:

press_exhibition|news_exhibition|press_artist|news_artist=$exhibition_id|$exhibition_id|$exhibition_artist|$exhibition_artist

This may not work exactly as you want because it will check if any of the variables are in any of the fields, but depending on your structure and possible options for these fields it might be ok. If not, I think you might have to do multiple selections and combine them like you suggested.

Here is an example of combining:

http://processwire.com/talk/topic/3055-replicate-mysql-union-with-selectors/?p=30033

In these cases I have actually gone with using standard SQL:

http://processwire.com/talk/topic/3053-possible-to-select-modifiedcreated/?p=30093

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

×
×
  • Create New...