filterBy - isTranslated on the text field

How can I make the filterBy code for the isTranslated applied to textarea on the page, named text?

I use a if statement inside the foreach loop now. But I need to filter this to make my tags etc. play nice. :smile:

Or use the custom filter I have added… onlyTranslated is it called.

It does not seem to work in the tags, the ->onlyTranslated()

The onlyTranslated is not checking the field that I want it to. But the isTranslated is.

Hey Jonathan, I don’t quite understand what you are asking, could you please provide your code. example?

Yes, of course. I have show you here two set of code. What works as expected and what is not.

I get the tags shown even if the content do not show in the list (the code ex. under). And I also get the wrong count. I have added I have added /site/plugins/filters.php with the following code:

// To just show relevant content for each language
pages::$methods['onlyTranslated'] = function($pages) {
  return $pages->filter(function($page) {
    return $page->content(site()->language()->code())->exists();

Do not work as expected
This is used in a snippet.

// fetch all tags
$tags = $pages->find('articles')->children()->visible()->onlyTranslated()->filterBy('text', '!=', '')->sortBy('tags', 'aesc')->filterBy('date', '<=', strtotime(date_default_timezone_get(date('Y-m-d'))))->pluck('tags', ',', true);
$p = kirby()->request()->params()->tag();
  <?php foreach($tags as $tag): ?>
	  // find how many that uses this tag
	  $count = page('articles')->children()->visible()->onlyTranslated()->filterBy('text', '!=', '')->filterBy('tags', '*=', $tag)->filterBy('date', '<=', strtotime(date_default_timezone_get(date('Y-m-d'))))->count();
	  // echo $tag . ': ' . $count; -- to show both tag and how many
		<a href="<?php echo url($site->language()->code() . '/articles/tag:' . urlencode($tag))?>" <?php ecco($tag == $p, ' class="active"') ?>>#<?php echo html($tag) ?><span class="count-items opa"style="opacity: 0.4;" > (<?php echo html($count) ?>)</span>
  <?php endforeach ?>

Works as expected
To list the “blog” I use this code, and it work as expected after adding the if statement inside the foreach loop. So is there a way to make it in to a filter instead to make the tag work with the isTranslated() function?

          $articles = $pages->find('articles')
          ->filterBy('text', '!=', '')
          ->filterBy('date', '<=', strtotime(date_default_timezone_get(date('Y-m-d'))))

<?php foreach($articles as $article): ?>
  <?php if ($article->text()->isTranslated()): ?>
    // show the content
  <?php endif ?>
<?php endforeach ?>

Thank you @texnixe for being active here on a sunday. :blush: