Wordpress使用不同标题的前端添加帖子

I want to create system to insert wordpress post from front-end to logged user. But I have checked same title post many times added by different user. How I add error message if post title already exist

Here is my code

 $u_id = get_current_user_id(); 
   $my_post = array(
   'post_title'    => 'title',
   'post_content'  => 'this is post content',
   'post_status'   => 'publish',
   'post_author'   => $u_id,
   'post_type'     => 'customer_post',
);

$post_ID = wp_insert_post( $my_post );

You can prevent this by checking some condition. You should try this. Wrap your code within this condition, it will not allow post with same title.

if (!get_page_by_title($title, 'OBJECT', 'post') ){

  //your code goes here.

 }