0

I am getting this fatal error when I try to add a new post, page or CPT.

Warning: Attempt to read property "post_type" on null in /public_html/wp-includes/post.php on line 7502

Warning: Attempt to read property "post_type" on null in /public_html/wp-includes/post.php on line 7503

Warning: Attempt to read property "ID" on null in /public_html/wp-includes/post.php on line 7507

Warning: Attempt to read property "post_type" on null in /public_html/wp-includes/post.php on line 7762

Warning: Attempt to read property "post_type" on null in /public_html/wp-includes/theme.php on line 3596

Warning: Attempt to read property "post_type" on null in /public_html/wp-includes/theme.php on line 3822

Warning: Attempt to read property "post_type" on null in /public_html/wp-includes/post.php on line 5448

Warning: Attempt to read property "ID" on null in /public_html/wp-includes/post.php on line 5448

Warning: Attempt to read property "post_type" on null in /public_html/wp-includes/post.php on line 4749

Fatal error: Uncaught Error: Attempt to assign property "post_content" on null in /public_html/wp-admin/includes/post.php:795 Stack trace: #0 /public_html/wp-admin/post-new.php(66): get_default_post_to_edit() #1 {main} thrown in /public_html/wp-admin/includes/post.php on line 795

When I re-activate my plugins, the error message changes to:

Warning: Attempt to read property "post_type" on null in /public_html/wp-includes/post.php on line 7502

Warning: Attempt to read property "post_type" on null in /public_html/wp-includes/post.php on line 7503

Warning: Attempt to read property "ID" on null in /public_html/wp-includes/post.php on line 7507

Warning: Attempt to read property "post_type" on null in /public_html/wp-includes/post.php on line 7762

Warning: Attempt to read property "post_type" on null in /public_html/wp-includes/theme.php on line 3596

Warning: Attempt to read property "post_type" on null in /public_html/wp-includes/theme.php on line 3822

Warning: Attempt to read property "post_type" on null in /public_html/wp-includes/post.php on line 5448

Warning: Attempt to read property "ID" on null in /public_html/wp-includes/post.php on line 5448

Warning: Attempt to read property "post_type" on null in /public_html/wp-includes/post.php on line 4749

Warning: Attempt to read property "post_status" on null in /public_html/wp-content/plugins/seo-by-rank-math/includes/modules/sitemap/class-cache-watcher.php on line 96

Warning: Attempt to read property "post_author" on null in /public_html/wp-content/plugins/seo-by-rank-math/includes/modules/sitemap/class-cache-watcher.php on line 100

Warning: Attempt to read property "post_author" on null in /public_html/wp-content/plugins/seo-by-rank-math/includes/modules/sitemap/class-cache-watcher.php on line 102

Fatal error: Uncaught TypeError: Elementor\TemplateLibrary\Source_Local::on_save_post(): Argument #2 ($post) must be of type WP_Post, null given, called in /public_html/wp-includes/class-wp-hook.php on line 326 and defined in /public_html/wp-content/plugins/elementor/includes/template-library/sources/local.php:1114 Stack trace: #0 /public_html/wp-includes/class-wp-hook.php(326): Elementor\TemplateLibrary\Source_Local->on_save_post() #1 /public_html/wp-includes/class-wp-hook.php(348): WP_Hook->apply_filters() #2 /public_html/wp-includes/plugin.php(517): WP_Hook->do_action() #3 /public_html/wp-includes/post.php(4760): do_action() #4 /public_html/wp-admin/includes/post.php(753): wp_insert_post() #5 /public_html/wp-admin/post-new.php(66): get_default_post_to_edit() #6 {main} thrown in /public_html/wp-content/plugins/elementor/includes/template-library/sources/local.php on line 1114

It seems the underlying problem is that $post is null.

To try and resolve, I have tried:

  • Updating all plugins
  • Disabling all plugins
  • Changing the theme
  • Re-installing WordPress (via wp-admin/update-core.php)
  • Re-uploading root / files and /wp-admin and /wp-includes folders
  • Checked database user permissions

This issue may coincide with me migrating the site to a new host server a couple of weeks ago, as this is the first post I have tried to add since then.

The site is running on PHP 8.1, but I have other sites running on the same server with the same PHP version that don't have this issue.

Can anyone advise why I am getting this issue and how to resolve?

8
  • Probably Elementor, try Regenerating CSS and media in Elementor settings Commented Mar 19 at 12:40
  • I've just tried Regenerate Files & Data which is in wp-admin > Elementor > Tools, but it hasn't fixed the problem. As I mentioned, this problem persists even if I disable all plugins. Commented Mar 19 at 18:52
  • 1
    Since you changed servers, did you check the "MU" (must use) plugins folder? When you install in some environments (godaddy, wpengine, etc.), they install must use plugins which may cause issues. Be sure to remove all of these folders when you are trying to get back to basics to trouble shoot
    – Adam
    Commented Mar 20 at 20:57
  • 1
    During website migration, AUTO_INCREMENT values within database tables are often getting lost. Within [prefix]_posts if you check the structure, do you see the ID column having AUTO_INCREMENT value?
    – Mowar
    Commented Mar 21 at 15:00
  • @Adam, Thanks but I don't seem to have an MU plugins folder. Commented Mar 21 at 19:44

3 Answers 3

1

I've fixed the problem now. I got hold of my old database dump file from the old server.

The reason the indexes weren't added is because the sql contained rows like:

CREATE ALGORITHM=UNDEFINED DEFINER=`xxxxxxxx`@`localhost` SQL SECURITY DEFINER VIEW `wp_

...which was not getting executed due to insufficient user permissions. This meant the consequent indexing lines were not executed either.

Solution was to comment out those lines, clear the new database then re-import. It's all good now and I can add posts again. :-)

0

Problem within the Elementor plugin, specifically in the Source_Local::on_save_post() method. The error states that the second argument passed to this method $post must be of type WP_Post, but it is receiving null instead.

If you're using any cache plugin, please ensure to purge all caches before and after updating the Elementor plugin and also try changes permalink

If the post name is already set in the permalink settings, update it to 'Plain' text, save the changes, then switch back to the 'Post name' option, save again, and make sure to clear the cache from both your caching plugin and your browser before testing

Settings → Permalinks → plain


Settings → Permalinks → Post
1
  • Thanks Vijay. I've now tried those, but to no avail. Please see my latest comment on the question. Commented Mar 24 at 14:19
0
+500

During website migration, AUTO_INCREMENT values within database tables are often getting lost. Within [prefix]_posts if you check the structure, do you see the ID column having AUTO_INCREMENT value?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.