• Hi,

    I was hoping you could confirm that when a WP_Query uses “suppress_filters” false in the query, that Polylang will update the returned posts array from WP_Query->query() to make sure the returned posts match the current locale (using switch_to_locale() and restore_previous_locale() before and after the query)?

    An example query would be:

    Array
    (
        [has_password] =>
        [order] => DESC
        [orderby] => date
        [post_status] => publish
        [post_type] => any
        [paged] =>
        [posts_per_page] => -1
        [no_found_rows] => 1
        [suppress_filters] =>
        [meta_query] => Array
            (
                [relation] => AND
                [0] => Array
                    (
                        [key] => _wpsso_head_info_og_type
                        [value] => product
                        [compare] => =
                        [type] => CHAR
                    )
    
                [1] => Array
                    (
                        [key] => _wpsso_head_info_is_noindex
                        [value] => 1
                        [compare] => !=
                        [type] => CHAR
                    )
    
                [2] => Array
                    (
                        [key] => _wpsso_head_info_is_redirect
                        [value] => 1
                        [compare] => !=
                        [type] => CHAR
                    )
    
            )
    
        [fields] => ids
    )

    Thanks,

    js.

Viewing 1 replies (of 1 total)
  • Plugin Author Chouby

    (@chouby)

    Hello,

    switch_to_locale() has no impact on how Polylang filters the query. The reason is that it’s possible to have several languages using the same locale (and in Polylang Pro a language can also have several locales). So the language used to filter the content and the locale used to load WordPress translations are handled seprately.

    By default, the query is filtered by the current language which is stored in PLL()->curlang. You can access to it with pll_current_language() . Switching the language, here to English can be done with: PLL()->curlang = PLL()->model->get_language( 'en' ) .

    If you need to query posts in a language different than the current language, you don’t need to switch it, you can specify the parameter lang in the WP_Query.

Viewing 1 replies (of 1 total)

The topic ‘Does Polylang support WP Query with “meta_query” args?’ is closed to new replies.