when returns wp_errors or 0 , how to set conditional tag

I am making front-end post submit. and I almost completed.
I want to redirect to specific page after submitting post in front-end successfully.

I am using this function.

wp_insert_post( array $postarr, bool $wp_error = false )

and this returns :

The post ID on success. The value 0 or WP_Error on failure.

$post_id = wp_insert_post( $post_data );
if( !$post_id || ?? ){ 
    wp_redirect( site_url('/compledted/') );
}

This is my code to make.I just want to redirect when submitting post is successfully finished. but I exactly don’t know how to set if( ) conditions.
can you help me?
Thank you.

1 Answer
1

you can test an error like that

$post_id = wp_insert_post($post_data, TRUE);

if (is_wp_error($post_id)) { 
    // there is an error

}

wp_redirect(site_url('/compledted/'));
exit();

Leave a Comment