• Resolved hupe13

    (@hupe13)


    I’m using a similar code like https://geek.hellyer.kiwi/2018/08/02/creating-fake-wordpress-pages/ to generate a page on the fly. I get some php errors since update to WP 6.1:

    PHP Warning: Attempt to read property "post_type" on null in /wp-includes/link-template.php on line 4066
    PHP Warning:  Attempt to read property "post_type" on null in /wp-includes/link-template.php on line 4068

    The reason is, as I understand it, that the post doesn’t exist really and therefore a shortlink doesn’t exist. Is this a bug or should I change something in the code?

    Thank you very much.

    • This topic was modified 2 years ago by Jan Dembowski. Reason: Moved to Fixing WordPress, this is not an Everything else WordPress topic
Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter hupe13

    (@hupe13)

    Solved with

    function detect_fake_shortlink($return, $id, $context, $allow_slugs) {
    	$url = isset($_SERVER["SCRIPT_URL"]) ? $_SERVER['SCRIPT_URL'] : "";
    	if (strpos($url, "/fakeslug/") !== false ) {
    		return true;
    	}
    	return $return;
    }
    // add the filter
    add_filter( "pre_get_shortlink", "detect_fake_shortlink", 10, 4 );

    But now and even before is still the error:
    PHP Warning: Attempt to read property "post_parent" on null in /wp-includes/post-template.php on line 724

    Thread Starter hupe13

    (@hupe13)

    Set

    		$wp_query->is_page             = false;
    		$wp_query->is_singular         = false;
    Ryan Hellyer

    (@ryanhellyer)

    Thanks for spotting this problem!

    My colleague Nate Finch spotted this issue recently too and came to the same result via pre_get_shortlink filter.

    He also noticed that you need to change the ID from an integer to a string, although I’m not sure why this is required.

    I’ve updated the post with a class which includes the filter for the shortlink:
    https://geek.hellyer.kiwi/2018/08/02/creating-fake-wordpress-pages/

    I wouldn’t modify the query like that, as it is stating that the page is not actually a page. I suspect that may have some odd trickle down effects, like the is_page() function not behaving as intended and things like that.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘fake page doesn’t work with WP 6.1’ is closed to new replies.