• Resolved StarryMom

    (@starrymom)


    I am doing basic 302 redirects from a virtual URL (no “real” post or page) for example

    Redirect 302 /go/fluffykitten https://fluffykitten.com

    However, because there is no “real” page I get the following errors, and I am well aware this is a PHP 8* issue but I don’t want to downgrade.

    PHP Warning: Attempt to read property “post_parent” on null in /home/public_html/wp-includes/post-template.php on line 724

    PHP Warning: Attempt to read property “post_type” on null in /home/public_html/wp-includes/link-template.php on line 4068

    PHP Warning: Attempt to read property “post_type” on null in /home/public_html/wp-includes/link-template.php on line 4066

    I would love a solution or to be pointed in the direction of a solution!

Viewing 4 replies - 1 through 4 (of 4 total)
  • Moderator bcworkz

    (@bcworkz)

    A proper WP_Post object should always have correctly defined properties. null is not a correct property value in this context. This is not a PHP 8 specific issue, all that has possibly changed is the error level. I think previously it was a notice level error?

    The cause of the warnings is a get_post() call is returning null because it was passed an invalid ID. While one could argue that the core code could have more robust error checking prior to using a property, the root cause of the issue is passing an invalid ID. Pass a proper ID and the warnings will go away. Any error checking rightly belongs after the initial query, prior to calling the functions that are currently throwing errors.

    There’s apparently an issue with your redirects, they do not convey adequate information for WP to resolve the request into a specific existing post object. Or the resulting query vars have somehow become corrupted so that the query fails to find anything. Focus on why the requests are failing, not on why there are null values for properties.

    Thread Starter StarryMom

    (@starrymom)

    Because there is no existing post, it’s a virtual URL. It doesn’t exist. It’s just a way to trigger the redirect.

    I found similar issues, but I am not using any code besides the basic 302 .htaccess redirects.

    https://stackoverflow.com/questions/74613027/wordpress-virtual-page-trying-to-get-property-post-type-of-non-object

    https://www.ads-software.com/support/topic/fake-page-doesnt-work-with-wp-6-1/

    Now, it’s not a huge issue, it doesn’t cause any impact one way or another, but I was hoping to find a way to resolve it.

    Moderator bcworkz

    (@bcworkz)

    Well, normal WP permalinks don’t really exist on the server either, but they contain enough information for the CMS to find the requested data.

    If the redirected request does not somehow relate to an actual WP_Post object, then we shouldn’t be trying to get a related body class or shortlink for it. There ought to be some sort of conditional code that says if a post object is not requested or found, skip trying to get a body class or shortlink for it.

    Calls like that are typically from a template, so the template code may need modification. While an improper body class would make little difference, an improper shortlink cannot be a good thing. But if you are not making use of either one, the related calls should probably be commented out.

    Thread Starter StarryMom

    (@starrymom)

    It’s just the one line in my .htaccess file for a basic 302 redirect.

    I guess I will just have to live with it, but I appreciate you taking the time to respond to me.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Virtual URLs + PHP 8* = Null Issues’ is closed to new replies.