• Resolved arianfar

    (@arianfar)


    Hello to all dear ones
    I have a lot of the following error in the error log file:

    PHP Notice: Trying to get property ‘post_type’ of non-object in /home/***/public_html/***/wp-includes/class-wp-query.php on line 4338

    I put the part of the class-wp-query.php file that includes line 4338 below.

    public function is_singular( $post_types = '' ) {
    if ( empty( $post_types ) || ! $this->is_singular ) {
    return (bool) $this->is_singular;
    }
    $post_obj = $this->get_queried_object();
    line 4338 ===>	return in_array( $post_obj->post_type, (array) $post_types, true );
    }

    All my plugins and my template are up-to-date
    If possible, guide me on what to do.
    Thank you very much

    • This topic was modified 3 years, 3 months ago by arianfar. Reason: i have a mistake

    The page I need help with: [log in to see the link]

Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter arianfar

    (@arianfar)

    Hello
    I have a lot of the following error in the error log file:

    Error at PHP version: 7.4
    PHP Notice: Trying to get property ‘post_type’ of non-object in ***/wp-includes/class-wp-query.php on line 4338

    Error at PHP version: 8.0
    PHP Warning: Attempt to read property “post_type” on null in ***/wp-includes/class-wp-query.php on line 4338

    I put the part of the class-wp-query.php file that includes line 4338 below.

    public function is_singular( $post_types = ” ) {
    if ( empty( $post_types ) || ! $this->is_singular ) {
    return (bool) $this->is_singular;
    }
    $post_obj = $this->get_queried_object();
    line 4338: return in_array( $post_obj->post_type, (array) $post_types, true );
    }

    I’m getting similar warnings under PHP 8 and also PHP 7.4, with any urls of my website, ending with /feed/;
    (the feed link gets displayed, however the warning is at the top of the page – each /feed page)
    I’ve searched for that warning message on Google and I can say came up with almost hundreds of websites indexed with that warning message in the results.
    So, it seems that’s a very common problem.
    The warning appears only in /feed/ pages, the mentioned line in php file contains:
    return in_array( $post_obj->post_type, (array) $post_types, true );

    Tested at all WordPress version: 5 and up

    All my WordPress and plugins and my template are up-to-date
    If possible, guide me on what to do.
    Thank you very much

    Moderator threadi

    (@threadi)

    In summary, this warning occurs when a /feed/-URL is called?

    Could you please verify if you are using PHP 8.0 or 8.1? You only wrote “PHP 8”. Both versions are supported by WordPress only as “beta support”: https://make.wordpress.org/core/handbook/references/php-compatibility-and-wordpress-versions/

    Furthermore you could test if disabling plugins helps to get rid of the message. The troubleshoot mode of this plugin can help: https://wordpress.org/plugins/health-check/

    Thread Starter arianfar

    (@arianfar)

    thank you very mach for replay
    yes, this warning occurs when a /feed/-URL is called.

    I’m currently using version PHP 7.4, but I’ve also tested version 8.0
    i disable plugings but when i visit this url:

    https://sonarweb.ir/sonarweb.ir/feed/

    error added to error_log file

    i install health-check plugin and test all plugins
    The errors comes from WooCommerce!
    WooCommerce is up to date

    Moderator threadi

    (@threadi)

    Then I would recommend to ask the WooCommerce-support: https://wordpress.org/support/plugin/woocommerce/

    Thread Starter arianfar

    (@arianfar)

    @threadi ok
    thank you again

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘PHP Notice ‘post_type’ of non-object in class-wp-query.php line 4338’ is closed to new replies.