froot Posted December 1, 2023 Share Posted December 1, 2023 is there a way to select pages by some (usually the current, or user?)-language specific value only? I'm aware that there's a method that I can use, but I'd prefer to use a selector, if possible. so instead of $results = new WireArray; $query = "banana"; $indexed = $pages->find("template=some_template"); foreach ($indexed as $p) { if ($p->getLanguageValue("english", "title|headline[preview|body") == $query { $results->add($p); } } I'd like to something like: $query = "banana"; $results = $pages->find("template=some_template, title|headline|preview|body=LanguageValue("english", $query)"); or $results = $pages->find("template=some_template, title_1021|headline_1021|preview_1021|body_1021=$query"); thanks for help! Link to comment Share on other sites More sharing options...
bernhard Posted December 2, 2023 Share Posted December 2, 2023 You can set the language before the $pages->find() operation: 1 Link to comment Share on other sites More sharing options...
da² Posted December 2, 2023 Share Posted December 2, 2023 28 minutes ago, bernhard said: You can set the language before the $pages->find() operation: But find() searches in current language AND default one. I assume OP wants to search only in one language. https://processwire.com/docs/multi-language-support/multi-language-fields/#how-language-fields-work Quote Because the user's current language is Dutch, the following API call matches any pages that contain the phrase "welkom vrienden" (welcome friends) in the Dutch body field OR the default body field. 1 1 Link to comment Share on other sites More sharing options...
bernhard Posted December 2, 2023 Share Posted December 2, 2023 Ah sorry, you are right! ? I'd have an idea but I'm on the go, so let's see if others know a good solution in the meantime. 1 Link to comment Share on other sites More sharing options...
froot Posted December 2, 2023 Author Share Posted December 2, 2023 7 hours ago, da² said: I assume OP wants to search only in one language. yes, exactly Link to comment Share on other sites More sharing options...
bernhard Posted December 3, 2023 Share Posted December 3, 2023 I don't know of a PW way to do it, but you can quite easily query the DB directly: <?php // do proper sanitization when using direct SQL queries!! $sql = "SELECT pages_id FROM field_title WHERE data1034 LIKE '%plan%'"; $result = $database->query($sql); $pageid = $result->fetch(\PDO::FETCH_COLUMN); This returns 1170 for $pageid So if you modify the query to search for "Paket" in "data1034" this would return false. With a regular PW page selector it would still return 1170 as it also searches in the "data" column. Note that this query does not take any access control into account. 1 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