fruid Posted October 5, 2020 Share Posted October 5, 2020 which selector would select all items where a certain field is not empty? foreach ($items as $item) : echo $item->numChildren("body!=''"); endforeach; I think it's clear for a human just by looking at this what I'm trying to do, doesn't work though. I have to add, it's a multilingual field so the same field in another language might not be empty, not sure that's relevant though… Thanks for help! Link to comment Share on other sites More sharing options...
eydun Posted October 5, 2020 Share Posted October 5, 2020 Maybe some hints in this thread: Link to comment Share on other sites More sharing options...
fruid Posted October 5, 2020 Author Share Posted October 5, 2020 Thanks for hints, it works but not always. Anyhow, what I'm trying to do is to return the number of descendants (with a non-empty body-field) for each language on the same page. Here's what I'm doing… foreach($languages as $language) : $hreflang = $homepage->getLanguageValue($language, 'name'); $url = "/$hreflang/$page->name/"; $descendants = $pages->get($url)->descendants("template=cast, body!="); $total = count($descendants); $total = "($total events)"; <a hreflang="<?=$hreflang;?>" href="<?=$url;?>"><?=$language->title; ?></a> <?=$total;?> endforeach; Somehow it ignores the specific path I'm using to find the descendants and translates it to the currently active language, thus returning the same results for each language. I can tell because when I echo all the results… foreach ($descendants as $d) : echo $d->url; endforeach; it always returns: /en/page-name/ and never /de/page-name/ Am I at least right in my assumption? Thanks for help! Link to comment Share on other sites More sharing options...
Matzn Posted October 6, 2020 Share Posted October 6, 2020 Maybe, you must switch the language by $language->get('de'); and after $pages->find https://processwire.com/docs/multi-language-support/multi-language-fields/#getting-and-setting Link to comment Share on other sites More sharing options...
fruid Posted October 6, 2020 Author Share Posted October 6, 2020 switch the language inside the foreach so it switches the user's language each time it returns the variable? The thing is, we might add more languages later, so I'd like to find a solution that will include all the languages from the get go. Link to comment Share on other sites More sharing options...
fruid Posted October 12, 2020 Author Share Posted October 12, 2020 I got the empty-body requirement working, simply with a selector like ("body!=") – works fine. However, still struggling to return results in one language on another language, i.e. showing german results with no empty body on the english site. I followed this advice: On 10/6/2020 at 5:34 PM, Matzn said: https://processwire.com/docs/multi-language-support/multi-language-fields/#getting-and-setting and here's my code $language = $user->language; // save the user's language $languages = $page->getLanguages(); $user->language = $languages->get("de"); // returns 'Deutsch' $descendants = $page->descendants("template=cast, body!="); $total = count($descendants); $total = "(".$total." ".__('events').")"; echo $user->language->title.' '.$total; // returns 'Deutsch: (0 events)' when on english page :( $user->language = $language; // restore the user's language but it still doesn't work. Any ideas? I don't know how to select the german version of the page nor how to loop them. 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