mel47 Posted February 3, 2017 Share Posted February 3, 2017 Hi, I'm searching, without success, to use all values of the pageArray inside a selector : foreach($page->alias as $al) { $publis = $pages->find("template=publication, categ_publi=$c, author.title={$page->title}|{$al->title}") } it doesn't work, but I have no idea how to get it. Thanks Link to comment Share on other sites More sharing options...
Macrura Posted February 3, 2017 Share Posted February 3, 2017 What is the $c - is that your pageArray? also, this is not much to go in, can you explain more? 1 Link to comment Share on other sites More sharing options...
mel47 Posted February 3, 2017 Author Share Posted February 3, 2017 Sorry, I should have remove this selector, since it's not the point. Author is a PageReference field found on publication template. The field alias is a PageReference field from the template member. I want to be able to select publications for an author either by its name ($page->title) or from their alias (author could have 2 or 3 differents surnames; $page->alias). I know how to use a foreach to get a single page, but how to apply in case of a selector? $publis = $pages->find("template=publication, author.title=??") Digging around while writing this explanation, I found this $publis = $pages->find("template=publication, author.id={$page->alias}) //works ->33 pages $publis = $pages->find("template=publication, author.title={$page->title}) //works ->82 pages //but how come this doesn't work ->0page $publis = $pages->find("template=publication, author.id={$page->alias}, author.title={$page->title}) How I can combine both results in one selector? Link to comment Share on other sites More sharing options...
kongondo Posted February 3, 2017 Share Posted February 3, 2017 I am not sure I follow either but I'll have a go . Is $page->alias a string or an integer? I am curious since you do this: author.id=$page->alias. Did you create your own field called id or is that the inbuilt page ID? I don't understand the foreach question. If what you are after is matching multiple values or multiple fields, then what we use are pipes |. See this docs. You say you would like to match publications by either name or their alias. However, the examples you give are not using or selectors; they are using AND selectors (i.e. comma separated selectors). See those docs for the differences. 1 Link to comment Share on other sites More sharing options...
Robin S Posted February 3, 2017 Share Posted February 3, 2017 7 hours ago, mel47 said: I'm searching, without success, to use all values of the pageArray inside a selector : foreach($page->alias as $al) { $publis = $pages->find("template=publication, categ_publi=$c, author.title={$page->title}|{$al->title}") } it doesn't work, but I have no idea how to get it. You could do this as follows: $titles = $page->alias->implode('|', 'title', array('append' => '|')); $titles .= $page->title; $publis = $pages->find("template=publication, categ_publi=$c, author.title=$titles"); 2 Link to comment Share on other sites More sharing options...
mel47 Posted February 4, 2017 Author Share Posted February 4, 2017 Thanks @Robin S it's really what I wanted! 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