• KLicheR

    (@klicher)


    polylang-1.6.5

    I got a notice when I tried to use the function pll_the_languages(array('raw' => true)) within the hook wp: Notice: Undefined property: WP_Query::$queried_object_id in /.../wp-includes/query.php on line 3960.

    I patched the file frontend/frontend-links.php to use the get_queried_object_id function instead of directly trying to access the property like this: $wp_query->queried_object_id.

    The patch

    diff --git a/frontend/frontend-links.php b/frontend/frontend-links.php
    index f5c7e78..89f3b40 100644
    --- a/frontend/frontend-links.php
    +++ b/frontend/frontend-links.php
    @@ -231,17 +231,18 @@ class PLL_Frontend_Links extends PLL_Links {
                    global $wp_query;
                    $qv = $wp_query->query_vars;
                    $hide = $this->options['default_lang'] == $language->slug && $this->options['hide_default'];
    +               $queried_object_id = $wp_query->get_queried_object_id();
    
                    // post and attachment
    -               if (is_single() && ($this->options['media_support'] || !is_attachment()) && ($id = $this->model->get_post($wp_query->queried_object_id, $language)) && $this->current_user_can_read($id))
    +               if (is_single() && ($this->options['media_support'] || !is_attachment()) && ($id = $this->model->get_post($queried_object_id, $language)) && $this->current_user_can_read($id))
                            $url = get_permalink($id);
    
                    // page for posts
                    // FIXME the last test should be useless now since I test is_posts_page
    -               elseif ($wp_query->is_posts_page && !empty($wp_query->queried_object_id) && ($id = $this->model->get_post($wp_query->queried_object_id, $language)) && $id == $this->model->get_post($this->page_for_posts, $language))
    +               elseif ($wp_query->is_posts_page && !empty($queried_object_id) && ($id = $this->model->get_post($queried_object_id, $language)) && $id == $this->model->get_post($this->page_for_posts, $language))
                            $url = get_permalink($id);
    
    -               elseif (is_page() && ($id = $this->model->get_post($wp_query->queried_object_id, $language)) && $this->current_user_can_read($id))
    +               elseif (is_page() && ($id = $this->model->get_post($queried_object_id, $language)) && $this->current_user_can_read($id))
                            $url = $hide && $id == $this->model->get_post($this->page_on_front, $language) ? $this->links_model->home : get_page_link($id);
    
                    elseif (!is_tax('post_format') && !is_tax('language') && (is_category() || is_tag() || is_tax()) ) {

    Thanks

    https://www.ads-software.com/plugins/polylang/

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

    (@chouby)

    Hi!

    Thank you for your suggestion. I will update the code.
    EDIT: Could you tell me on what kind of page you get the error?

Viewing 1 replies (of 1 total)
  • The topic ‘Patch for fixing a notice’ is closed to new replies.