Site icon Hip-Hop Website Design and Development

wp_insert_post all the time returns 0 on one web site, intensive testing achieved, cannot get to the underside

I’ve two websites. One, a recent set up, the opposite an current web site with errors/white display of dying on the wp-admin/post-new.php display. I’ve disabled the entire energetic plugins, and enabled a default theme, and am nonetheless getting these errors (as a result of the draft publish is just not created correctly within the DB in the course of the web page load).

Discover: Making an attempt to get property 'post_type' of non-object 
Warning: Creating default object from empty worth
Discover: Making an attempt to get property 'post_status' of non-object
Discover: Making an attempt to get property 'ID' of non-object

I’ve tracked this all the way down to a difficulty with wp_insert_post() when loading the wp-admin/post-new.php display. For testing, I added a wp_die( print_r( $wpdb ) ); within the wp-includes/publish.php core file (right here). This outputs a number of details about the database question. No errors are current, and it says [rows_affected] => 1, [insert_id] => 0, and the return of wp_insert_post() is all the time 0.

I can not work out why with a default core theme, no plugins energetic, no mu-plugins listing and no core recordsdata altered, wp_insert_post() is all the time returning 0. The publish is inserted into the database, however it all the time has a publish ID of 0 and the post-new.php display white screens. When I’ve WP_DEBUG enabled, the above errors are current. I’ve a sense it has to do with the one database, however I do not see any errors that will point out so. Each DBs are InnoDB and just about equivalent apart from the info held inside them.

My very fundamental code to check wp_insert_post() is as follows, and as acknowledged works on one web site and never the opposite.

$my_post = array(
    'post_title'    => 'take a look at',
    'post_content'  => '',
    'post_status'   => 'publish',
    'post_author'   => 1,
);

// Insert the publish into the database
$take a look at = wp_insert_post( $my_post );

wp_die( 'New ID: ' . $take a look at );

On the non-working web site, the publish is inserted into the database as publish 0 and set to auto draft.

Var Dump from Damaged $wpdb

Right here is the var_dump of the $wpdb return within wp_insert_post() within the core file linked above: https://pastebin.com/CGGv5q4N

As you may see there aren’t any seen errors, and it appears to be like just like the publish ought to have been assigned a publish ID, as a result of it is within the DB, however it’s all the time publish ID 0.

Var Dump from Working $wpdb

https://pastebin.com/QTUVfdHR