Archived topic
Post query loop and languages
5 replies · Started by Alfredo on March 24, 2023
I'm creating a Block - Content template for my blog posts and I'm trying to add a GB query loop at the end for displaying posts in the same category.
The visual editor is displaying only posts in English but when I see the page live it is displaying all the posts in the 3 languages. How can I prevent it from doing that? I'm using Polylang and I have 3 languages.
Hi Alfredo,
For clarity, can you provide a screenshot of the issue from your end?
Uploading Screenshots: https://docs.generatepress.com/article/using-the-premium-support-forum/#uploading-screenshots
Visual editor: https://postimg.cc/QF4vychg (only English)
Query loop block: https://postimg.cc/94GZM51L
Live blog post: https://postimg.cc/QFxRmfGx (all languages)
Hi there,
what parameters does the query loop have ?
Only the ones you can see in the query loop screenshot.
- Taxonomies -> Categories (current post terms)
- Exclude current post
Ok, try adding this PHP Snippet to your site:
add_filter( 'generateblocks_query_loop_args', function( $query_args, $attributes ) {
// Check your logic to apply the filtering only to specific loop
if (
! empty( $attributes['className'] ) &&
strpos( $attributes['className'], 'polylang' ) !== false
) {
// Merge the current $query_args which contains arguments defined in the editor with your ordering arguments
return array_merge( $query_args, array(
'lang' => pll_current_language(),
) );
}
return $query_args;
}, 10, 2 );
And then edit the Query Loop, and select its Grid Block and give that an Advanced > Additional CSS Class of: polylang