I have ran a php code to remove some pages of the database, the code worked fine and i have left with the optmised pages i needed.
However, now i can’t create new pages at all.
This happened with 2 sites now, The first website (catering.jobs), the fornt end gives:
Warning: Attempt to read property "post_type" on null in /wp-includes/post.php on line 7618
Warning: Attempt to read property "post_type" on null in /wp-includes/post.php on line 7619
Warning: Attempt to read property "ID" on null in /wp-includes/post.php on line 7623
Warning: Attempt to read property "post_type" on null in /wp-includes/post.php on line 7868
Warning: Attempt to read property "post_type" on null in /wp-includes/theme.php on line 3532
Warning: Attempt to read property "post_type" on null in /wp-includes/theme.php on line 3757
Warning: Attempt to read property "post_type" on null in /wp-includes/post.php on line 5405
Warning: Attempt to read property "ID" on null in /wp-includes/post.php on line 5405
Warning: Attempt to read property "post_type" on null in /wp-includes/post.php on line 4706
Warning: Attempt to read property "post_type" on null in /wp-admin/includes/post.php on line 709
Fatal error: Uncaught Error: Attempt to assign property "post_content" on null in /wp-admin/includes/post.php:748
Stack trace: #0 /wp-admin/post-new.php(66): get_default_post_to_edit('page', true) #1 {main} thrown in /wp-admin/includes/post.php on line 748
The error log gives:
Got error '
PHP message: PHP Warning: Attempt to read property "post_type" on null in /wp-includes/post.php on line 7618
PHP message: PHP Warning: Attempt to read property "post_type" on null in /wp-includes/post.php on line 7619
PHP message: PHP Warning: Attempt to read property "ID" on null in /wp-includes/post.php on line 7623
PHP message: PHP Warning: Attempt to read property "post_type" on null in /wp-includes/post.php on line 7868
PHP message: PHP Warning: Attempt to read property "post_type" on null in /wp-includes/theme.php on line 3532
PHP message: PHP Warning: Attempt to read property "post_type" on null in /wp-includes/theme.php on line 3757
On the second website (recruitment-agency.london), the frontend gives:
Fatal error: Uncaught Error: Attempt to assign property "post_content" on null
in /wp-admin/includes/post.php on line 748
Call stack:
get_default_post_to_edit()
wp-admin/post-new.php:66
And the error log gives:
Got error '
PHP message: PHP Fatal error: Uncaught Error: Attempt to assign property "post_content" on null in /wp-admin/includes/post.php:748\n
Stack trace:\n#0 /wp-admin/post-new.php(66): get_default_post_to_edit('page', true)\n#1 {main}\n thrown in /wp-admin/includes/post.php on line 748'
I have done the following:
1- Cleared the cache on server and browser
2- Tried with 2020 theme with no plugins active.
3- Repaired and optimised the database tables.
4- Reinstalled wordpress the latest version.
5- Contatced my hosting support and they had no idea.
Can anyone give me a hint please?
Update: the php code to remove the not optimised pages is here:
<?php
// Read ral-opt-slugs.txt file and store slugs in array
$slugs = file('ral-opt-slugs.txt', FILE_IGNORE_NEW_LINES);
// Connect to database
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "test";
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
// Ping the MySQL server to ensure the connection is still alive
if (!mysqli_ping($conn)) {
die("Connection lost.");
}
// Delete pages that are not in the list of slugs and not reserved
$sql = "SELECT * FROM wp_posts WHERE post_type = 'page' AND post_name NOT IN ('" . implode("', '", $slugs) . "') AND post_name NOT LIKE 'media%' AND post_name NOT LIKE 'plugins%' AND post_name NOT LIKE 'themes%'";
$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result) > 0) {
while ($row = mysqli_fetch_assoc($result)) {
$id = $row['ID'];
$sql = "DELETE FROM wp_postmeta WHERE post_id = '$id'";
mysqli_query($conn, $sql);
$sql = "DELETE FROM wp_posts WHERE ID = '$id'";
mysqli_query($conn, $sql);
echo "Deleted page with slug: " . $row['post_name'] . "\n";
}
} else {
echo "No pages found for deletion.\n";
}
// Close database connection
mysqli_close($conn);
?>
Regards