I want to update a post using

wp_update_post( $my_post );

How can I check if it was successful? Should it return the post ID on successful update?
I’m trying this:

$post_id = wp_update_post( $my_post );
if ( $post_id ) {
  echo "successful";
} else {
   echo "fail";
}

The above code does not return any ID, so i wanted to make sure if it is correct.

1 Answer
1

You can use the $wp_error argument to return an error message.

$post_id = wp_update_post( $my_post, true );

if ( is_wp_error( $post_id ) ) {
     echo $post_id->get_error_message();
}
else {
     echo 'true';
}

Leave a Reply

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