I am building a function in wordpress that reads an XML file and imports 100-500 events as a post type to wordpress. The events have a lot of meta data that is saved as post meta. One of the meta data items will be a unique (string) identifier from each event in the XML feed.
The importer will be set up as a wp_cron, to make sure that our database is up to date.
In order to make sure that i dont add duplicates every time the import runs, I would like to check if a post with the unique identifier already exists -- if it does it will update, otherwise insert.
This is how the wp_insert_post function works with the post id's. If a post with the specified ID already exists, it will update instead of inserting.
How can I best achieve this? Can I run a get_posts() with a meta query on every entry? Will that be efficient or expensive performance wise? Would it result in to many sql queries?
Any advice on how to do this check would be much appreciated.