October CMS resources and help articles

Simple and to the point. Optimized by the community.

Find all Blog Posts that have a translation in a specific locale

0
by mjauvin, last modified on March 2nd, 2020

If you need to find all Blog Posts that have a translation in a specific locale, use this:

$locale = 'fr';
$posts =  RainLab\Blog\Models\Post::whereHas('translations', function ($query) use ($locale) {
    $query->where('locale', $locale)->whereRaw("attribute_data not like '%\"content\":\"\"%'");
})->get();

Note: this obviously does not work for the DEFAULT locale

Discussion

1 comment

0
alex
Post on June 28th, 2020 7:16 AM

Hi, how do you add this code? On the blogposts partial? on the page where there will be displayed? Merci!

We use cookies to measure the performance of this website. Do you want to accept these cookies?