[Resolved] Polylang GP conflict

Home Forums Support [Resolved] Polylang GP conflict

Home Forums Support Polylang GP conflict

Viewing 15 posts - 1 through 15 (of 16 total)
  • Author
    Posts
  • #479674
    John Dowling

    Hi Tom.
    Overall I am loving GP!

    I also have polylang installed to have both french and english. One problem.
    The search box works fine in english and delivers only english pages.
    On the french side it never finds anything.

    If I use the built-in wordpress search widget both languages work perfectly

    If I turn off polylang the GP search function works but delivers results from both languages.

    Can you helpÉ

    #479937
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    Any chance you can turn on the core search widget so I can inspect the code?

    Let me know 🙂

    #480506
    John Dowling

    Sure. I activated the search box in the footer of both languages.

    #480638
    Tom
    Lead Developer
    Lead Developer

    Just dove into their code a bit, let’s try this function:

    add_filter( 'generate_navigation_search_output', 'tu_polylang_navigation_search' );
    function tu_polylang_navigation_search( $search ) {
        if ( ! function_exists( 'pll_current_language' ) ) {
            return $search;
        }
    
        printf( // WPCS: XSS ok, sanitization ok.
            '<form method="get" class="search-form navigation-search" action="%1$s">
                <input type="search" class="search-field" value="%2$s" name="s" title="%3$s" />
            </form>',
            esc_url( home_url() ) . '/' . pll_current_language(),
            esc_attr( get_search_query() ),
            esc_attr_x( 'Search', 'label', 'generatepress' )
        );
    }

    Let me know 🙂

    #480734
    John Dowling

    Where does it go?

    #480821
    Leo
    Staff
    Customer Support

    One of these methods here: https://docs.generatepress.com/article/adding-php/

    Code snippet is usually what I use unless you are using a child theme.

    #480853
    John Dowling

    Installed Code snippet. Set to run everywhere. Sadly no luck

    #480921
    Tom
    Lead Developer
    Lead Developer

    I just dug through some of the Polylang documentation and made a change to the code above.

    Can you try it and let me know?

    Thanks!

    #480985
    John Dowling

    Now both languages don’t work. Any search give: Oops! That page can’t be found.
    (When the snippet is deactivated and you search for something that isn’t there you get “Nothing found”)

    #481224
    Tom
    Lead Developer
    Lead Developer

    Grr. Is the snippet still active?

    #481311
    John Dowling

    it is now.
    The search in english works. But if you then search from the results page you get the error message

    #481482
    Tom
    Lead Developer
    Lead Developer

    Alright, let’s try this again: https://generatepress.com/forums/topic/polylang-gp-conflict/#post-480638

    I believe I’m using the right function now.

    #481851
    John Dowling

    Works!! Thanks!

    Only bug is if you click on English when you are in the French search results page you get the file not found message. Then if you click again you go to english home page. Maybe that’s a separate language switch problem?

    #481857
    Tom
    Lead Developer
    Lead Developer

    That may be worth checking with Polylang support about. If it’s something we need to do on our end, I’ll see what I can do 🙂

    Thanks!

    #481912
    John Dowling

    I think I’ll leave it for now as not likely thing for people to do.
    Thanks for your help!!

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