Custom Post type doesn’t appear in search results

Finally I found the cause of this issue. It was simply because of Polylang plugin. As the plugin adds a taxonomy related to the language of the website to all posts, it adds a LEFT JOIN statement to the search query with a condition WHERE 1=1 AND post has that taxonomy id. As I didn’t add this taxonomy in the wp_insert_post function, none of these posts related to the post type I created can meet the condition in the query added by Polylang. Once I deactivated it, everything worked fine.