I have a foreach loop inserting posts. And I already have statements to check if post already exists by unique meta values. But somehow, often when site is loading slowly, something strange happens and duplicated posts are appearing. Same permalink but just with "-2" and "-3" and so on in the end of the url.
I would like to know if there is a hook or something to stop the
wp_insert_post() function from inserting the post if it detects that it has to add that to the permalink.