Question

I have a form in a page template that allows users to submit posts into a custom post type from the front-end:

$post = array(
    'post_status' => 'draft',
    'post_type' => 'stories',
    'post_content' => wp_kses_post( $story_content ),
    'post_title' => esc_attr( wp_kses( $story_title, array() ) ),
    'post_author' => 4,
);

// Insert story into db
$post_success = wp_insert_post( $post );

It works, but I receive these notices

PHP Notice:  Trying to get property of non-object in /Users/username/Sites/the_site/wp-includes/comment-template.php on line 776
PHP Notice:  Trying to get property of non-object in /Users/username/Sites/the_site/wp-includes/comment-template.php on line 793
PHP Notice:  Trying to get property of non-object in /Users/username/Sites/the_site/wp-includes/general-template.php on line 1645
PHP Notice:  Trying to get property of non-object in /Users/username/Sites/the_site/wp-includes/link-template.php on line 1106
PHP Notice:  Trying to get property of non-object in /Users/username/Sites/the_site/wp-includes/link-template.php on line 1148
PHP Notice:  Trying to get property of non-object in /Users/username/Sites/the_site/wp-includes/link-template.php on line 1106
PHP Notice:  Trying to get property of non-object in /Users/username/Sites/the_site/wp-includes/link-template.php on line 1148

I've looked at the files referenced, and it seems to be related to the comment_status and ping_status of the submitted post, however, I assume that the defaults for wp_insert_post should input values for those. Even when I set them in my args array, I get the notices. How to fix this to get rid of the notices?

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with wordpress.stackexchange
scroll top