Jump to content

Select pages by language specific value only


froot
 Share

Recommended Posts

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

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.

 

  • Like 1
  • Thanks 1
Link to comment
Share on other sites

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

LBG31zV.png

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.

  • Like 1
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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...