I’m using wp_insert_post function to insert a new post:

$result = wp_insert_post(array("post_title"=>"test1"), true);

When I echo the result of the function, I get the number 335. How can I see what is the meaning of this code. I tried this with no success:

$error = new WP_Error($result);
echo ($error->get_error_message($result));

1
1

335 is not an error message or code, it is the new post’s ID that is retuned, so in short, the new post you have inserted was given the ID of 335

UPDATE

wp_insert_post() already returns a WP_Error object on failure, so simply var_dump( $result ); would give you a specific error message on failure or the new post ID on success

Leave a Reply

Your email address will not be published. Required fields are marked *