is_wp_error()
.true
handle accordingly, for example trigger_error()
with message from WP_Error->get_error_message()
method.false
– proceed as usual.Usage:
1 2 3 4 5 6 7 8 9 10 11 | function create_custom_post() { $postarr = array(); $post = wp_insert_post($postarr); return $post; } $result = create_custom_post(); if ( is_wp_error($result) ){ echo $result->get_error_message(); } |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.