davo Posted June 8, 2014 Share Posted June 8, 2014 In the example below DMCstats_Language is a page select field which can contain multiple selections. I've cheated a little bit below just asking if the first selection in the array == english; it's likely but not always the case that english is in the first position. Is there an easy way to query the array to see if simply contains 'English'? $language = $page->DMC_select->DMCstats_Language->first()->title; if($language == "English") {$flying_message .= "English is one of the native languages of $country.";} Link to comment Share on other sites More sharing options...
teppo Posted June 8, 2014 Share Posted June 8, 2014 Well, you could always use has(). Depending on what these pages really are etc. try something like this: $english = $pages->get("template=language, title=English"); if ($page->DMC_select->DMCstats_Language->has($english)) { // do stuff } 3 Link to comment Share on other sites More sharing options...
davo Posted June 8, 2014 Author Share Posted June 8, 2014 Thank you. I'm almost there using this: $english = $pages->get("template=language, title*=English|english"); if(($page->DMC_select->DMCstats_Language > 0 ) && ($page->DMC_select->DMCstats_Language->has($english))) { $flying_message .= "English is one of the native languages of $country.";} This works if the selected language page 'has' English. Sadly, the person inputting the pages rather than reusing the exisiting values has done a shortcut by rather than adding English on one entry and then French on the next, they've created a single entry like this: "English, French". They've done this quite a few times. So I've got some data entries to clean up, but in the mean time I thought i'd use the selector as i've done above.. "title*=English"; hoping that it would match any with English in the title regardless of other mess surrounding it. But it doesn't seem to bring back any results unless it exclusively has English in the title. Have I used this selector incorrectly or misunderstood it's use? Thanks Link to comment Share on other sites More sharing options...
teppo Posted June 9, 2014 Share Posted June 9, 2014 There's a bit of difference between operators "*=" and "%=". Quoting from the documentation: *= Contains the exact word or phrase%= Contains the exact word or phrase (using slower SQL LIKE) [v2.1] In many cases %= is more "forgiving" and generally just finds more results than *=, so I'd try if that helps. It might also make more sense to search by name, which is often identical to title, just all lowercase characters and spaces etc. converted to dashes: // find with name and use %= (SQL LIKE oeprator): $english = $pages->get("template=language, name%=english"); // alternative approach if you know that there's "english" at the *beginning* of the name: $english = $pages->get("template=language, name^=english"); Link to comment Share on other sites More sharing options...
davo Posted June 9, 2014 Author Share Posted June 9, 2014 There's a bit of difference between operators "*=" and "%=". Quoting from the documentation: In many cases %= is more "forgiving" and generally just finds more results than *=, so I'd try if that helps. It might also make more sense to search by name, which is often identical to title, just all lowercase characters and spaces etc. converted to dashes: // find with name and use %= (SQL LIKE oeprator): $english = $pages->get("template=language, name%=english"); // alternative approach if you know that there's "english" at the *beginning* of the name: $english = $pages->get("template=language, name^=english"); Thank you, using the name field with %= seems to return the correct results now. Thanks 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