Duplicate posts from custom import
-
I work at a radio station and have built a plugin that automatically builds a playlist on our site from what plays on the radio. It starts by querying an XML playlist file output by our radio streaming server. If the plugin has not seen a song played at a specific time before, it will create a new post (itself a custom post type called “Song”) for that XML song entry. Then I have a shortcode that just runs a WP_Query for posts of type “Song” and outputs the most recent.
The problem is this: the XML is queried every time someone opens a page that calls the shortcode. When we get a lot of people visiting our site, we will end up with duplicate posts of the same song at the same time. I presume this is because two people happened to query the XML file and the WP_Query at the same time, which resulted in neither of them finding the song and so both of them adding the post. I’m trying to find a way to prevent this duplication from happening, but so far, I haven’t come up with much. Any ideas would be appreciated.
- The topic ‘Duplicate posts from custom import’ is closed to new replies.