I have a genuine mystery. With this code (in an ajax call):
file_put_contents(ABSPATH.'wp-content/debug.log', 'Inserting new note' . PHP_EOL, FILE_APPEND);
$post_id = wp_insert_post( array(
'post_title' => sanitize_text_field( $title ),
'post_status' => 'publish',
'post_type' => 'coursenote',
'post_content' => $_POST['data']['body']
), true );
file_put_contents(ABSPATH.'wp-content/debug.log', 'WTF' . PHP_EOL, FILE_APPEND);
I am seeing the new post in the database, but the wp_insert_post
function is somehow not returning (evidenced by fact that second file_put_contents is not doing anything.
I don’t know if it has to do with other ajax calls or something. Just really odd that everything is fine til wp_insert_post’s return.
Can anyone think of a reason why this could happen?
thanks,
Brian
Edit:
So I found the problem. Some really awful programmer had an exit;
call in a save_post
hook in a plugin. That resulted in the script not returning to the calling script (wp_insert_post
).
That awful programmer is the author of this question 🙂 And the offensive exit
is now a return