Site logo

[Support request] Post query loop and languages

Home Forums Support [Support request] Post query loop and languages

Home Forums Support Post query loop and languages

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #2579828
    Alfredo

    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.

    #2579832
    Fernando
    Customer Support

    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

    #2579978
    Alfredo

    Visual editor: https://postimg.cc/QF4vychg (only English)
    Query loop block: https://postimg.cc/94GZM51L

    Live blog post: https://postimg.cc/QFxRmfGx (all languages)

    #2580651
    David
    Staff
    Customer Support

    Hi there,

    what parameters does the query loop have ?

    #2581120
    Alfredo

    Only the ones you can see in the query loop screenshot.

    – Taxonomies -> Categories (current post terms)
    – Exclude current post

    #2581507
    David
    Staff
    Customer Support

    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

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.