无法成功检查数据库中是否存在带标题的帖子

In WordPress, I am trying to import posts from a CSV file. I want to check, if post with title already exist. I am trying to do this using a database query, but I am still able to import the same three posts from my example CSV file.

Following PHP code snippet is what I use for checking, if a post with title already exist:

$check_post_exists = function( $title ) use ( $wpdb, $postTypeArray ) {

        $posts = $wpdb->get_col( "SELECT post_title FROM {$wpdb->posts} WHERE post_type = '{$postTypeArray["custom-post-type"]}' AND post_status = 'publish'" );

        return in_array( $title, $posts );
    };

    foreach ( $posts() as $post ) {

        if ( $check_post_exists( $post["zoneid"] ) ) {
            continue;
        }

        $post["id"] = wp_insert_post( array(
            "post_title" => $post["zoneid"],
            "post_content" => $post["bemaerkning"],
            "post_type" => $postTypeArray["custom-post-type"],
            "post_status" => "publish"
        ));         
    }

What am I doing wrong or what am I missing here?

Use this code and let me know.

 $my_post = array(
 Array Data
    );  
   $post_id = wp_insert_post($my_post);
   add_post_meta($post_id, 'times', '1');    

I think its work for you