Title: Duplicate Events in Database
Last modified: April 10, 2018

---

# Duplicate Events in Database

 *  Resolved [Modmacro](https://wordpress.org/support/users/modmacro/)
 * (@modmacro)
 * [8 years ago](https://wordpress.org/support/topic/duplicate-events-in-database/)
 * Thanks for the great plugin! We have begun implementing this at our church and
   have encountered an issue with duplicate event records in the database. After
   doing a sync, I’ll inspect the records in the database and find several events
   that are duplicated. For example, looking at “Revelation Fitness” events using
   this SQL in MyPHP …
 * SELECT ID, post_content, post_title, post_status, post_modified, meta_key, meta_value
   FROM wp_posts, wp_postmeta
    WHERE wp_posts.post_title = ‘Revelation Fitness’ 
   AND wp_postmeta.post_id = wp_posts.ID AND wp_postmeta.meta_key = ‘date’ ORDER
   BY meta_value
 * … We find 30 records, each with a unique ID, but with several of them coming 
   as duplicate pairs. Have you seen this behavior before? I don’t see anyone else
   reporting this issue.
 * We are using:
    plugin version 1.0.4 WP version 4.9.5
 * thanks,
    Matt-

Viewing 10 replies - 1 through 10 (of 10 total)

 *  Plugin Author [Jared Cobb](https://wordpress.org/support/users/jaredcobb/)
 * (@jaredcobb)
 * [8 years ago](https://wordpress.org/support/topic/duplicate-events-in-database/#post-10172162)
 * Hi Matt,
 * I’ve not seen duplicates like this before. Would you mind checking the API response**
   directly** in order to confirm that CCB isn’t actually sending duplicates?
 * The easiest way to test this is to connect to the endpoint in your browser and
   inspect the items that are being returned. The format of the request would be:
 * `https://<username>:<password>@<subdomain>.ccbchurch.com/api.php?srv=public_calendar_listing&
   date_start=2018-04-11&date_end=2018-04-22`
 * Where <username> <password> are the API credentials and <subdomain> is your unique
   CCB church subdomain.
 * You can of course change the date range if needed (this is 2 weeks starting today).
 * One last thing to clarify, but I’m sure you probably know this… If an event is
   a recurring event, you _will_ get duplicates (in the sense that you’ll see multiple
   Event Names as posts in WordPress) but they would all have unique dates in their
   post meta.
 *  Plugin Author [Jared Cobb](https://wordpress.org/support/users/jaredcobb/)
 * (@jaredcobb)
 * [8 years ago](https://wordpress.org/support/topic/duplicate-events-in-database/#post-10172168)
 * Matt,
 * I have a couple other thoughts…
 * 1) I noticed you’re doing a SQL query to check for the duplicate events. Be aware
   that if any WordPress posts get _updated_ after a synchronization, you _will_
   get an additional duplicate record in `wp_posts` but the `post_status` would 
   be a `revision`. Do any duplicates have a `post_status` other than `publish` 
   perhaps?
 * 2) Another way we might confirm whether the CCB API is _sending_ duplicates versus
   the plugin _creating_ duplicates is to manually delete all of the event posts**
   in WordPress** and do a single sync. Then you can see if the data is clean. Next,
   do another sync and see if you get duplicates again.
    -  This reply was modified 8 years ago by [Jared Cobb](https://wordpress.org/support/users/jaredcobb/).
 *  Thread Starter [Modmacro](https://wordpress.org/support/users/modmacro/)
 * (@modmacro)
 * [8 years ago](https://wordpress.org/support/topic/duplicate-events-in-database/#post-10172268)
 * Hi Jared,
 * Thanks so much for the quick reply. Here’s the status on the tests you suggested…
 * Looking directly at the XML from the API, using the method you outlined above,
   there are NOT any duplicates coming through. I then confirmed that there are 
   still duplicates (for the same date range) in the database after doing a sync
   with the plugin.
 * Next, yes, I understand that recurring events (of which we have many) come through
   with the same title, but in SOME cases, we are also seeing them with the same
   title and date in the database (a duplicate).
 * Next, yes, I had previously confirmed that these duplicates are all marked with
   a post_status of “publish”.
 * Lastly, I went through and killed all events in the database, confirmed they 
   were all gone and did a sync. NO DUPLICATES.
 * Then I waited a little bit and did another sync, DUPLICATES ARE BACK. So back
   to square one. At this point there were 278 events in the DB with “publish” status.
 * Did another sync, now 291 events in the DB with “publish” status. More duplicates
   obviously.
 * Did another sync, now 305 events in the DB with “publish” status.
    Did another
   sync, now 315 events in the DB with “publish” status.
 * … you get the idea. We are accumulating a larger and large number of dups with
   each sync. Interestingly, there are zero events with a status other than publish.
   Should there be some with a different status, like revision?
 * Man, any help you can offer is greatly appreciated. We’ve hit a wall.
 * thanks!
    Matt-
 *  Plugin Author [Jared Cobb](https://wordpress.org/support/users/jaredcobb/)
 * (@jaredcobb)
 * [8 years ago](https://wordpress.org/support/topic/duplicate-events-in-database/#post-10174033)
 * Matt,
 * Thanks for confirming all of that! The plugin definitely seems to be causing 
   the issue, and for some reason I haven’t been able to replicate it on my church’s
   account.
 * Would you be able to create another API user for me and grant the user rights
   to the `public_calendar_listing` service? This way I can try to replicate the
   issue using the same data. (And once I get this fixed you can delete my API user).
 * Also, do you know what PHP version you’re running? If not you can temporarily
   install this plugin [https://wordpress.org/plugins/wordpress-php-info/](https://wordpress.org/plugins/wordpress-php-info/)
   and then remove it.
    -  This reply was modified 8 years ago by [Jared Cobb](https://wordpress.org/support/users/jaredcobb/).
 *  Plugin Author [Jared Cobb](https://wordpress.org/support/users/jaredcobb/)
 * (@jaredcobb)
 * [8 years ago](https://wordpress.org/support/topic/duplicate-events-in-database/#post-10174170)
 * Matt,
 * Disregard my last post, I’m actually able to replicate this. It seems there’s
   a bug if the **data range** starts in the past (i.e. in the settings if the “
   How Far Back” setting is greater than 0).
 * I’ll have time to debug this later today and figure out what’s wrong. I’ll be
   able to publish an update (hopefully today or tomorrow).
 * Thanks again for reporting this!
 *  Thread Starter [Modmacro](https://wordpress.org/support/users/modmacro/)
 * (@modmacro)
 * [8 years ago](https://wordpress.org/support/topic/duplicate-events-in-database/#post-10174602)
 * Awesome, we’ll hang on until we hear back from you.
 * In case it helps, here are versions we are using:
 * OS: linux
    Apache: 2.4.33 PHP: 5.6.35 MySQL: 5.6.38
 * Thanks!
    Matt-
    -  This reply was modified 8 years ago by [Modmacro](https://wordpress.org/support/users/modmacro/).
 *  Plugin Author [Jared Cobb](https://wordpress.org/support/users/jaredcobb/)
 * (@jaredcobb)
 * [8 years ago](https://wordpress.org/support/topic/duplicate-events-in-database/#post-10174667)
 * Great. This actually had nothing to do with the date range starting in the past
   after all.
 * As part of the synchronization process, the plugin fetches all the _existing_
   event posts and compares them to the API response. It turns out there is a scenario
   where fetching the posts can result in not actually getting **all** of them (
   and then the plugin thinks those events are “missing” and needs to insert them
   again).
 * I’m also surprised this hasn’t come up before. It’s possible something has changed
   in a recent WordPress update with how `WP_Query` handles batched & looped queries(
   which is how I’m fetching the existing posts for performance reasons).
 * I have a fix in place, but I won’t be able to publish a new version until this
   evening.
    -  This reply was modified 8 years ago by [Jared Cobb](https://wordpress.org/support/users/jaredcobb/).
 *  Plugin Author [Jared Cobb](https://wordpress.org/support/users/jaredcobb/)
 * (@jaredcobb)
 * [8 years ago](https://wordpress.org/support/topic/duplicate-events-in-database/#post-10176203)
 * [@modmacro](https://wordpress.org/support/users/modmacro/) I published a new 
   version that fixes this issue (1.0.5). When you have a chance can you confirm
   it’s working for you as well? Thanks again for reporting this.
 * Jared
 *  Thread Starter [Modmacro](https://wordpress.org/support/users/modmacro/)
 * (@modmacro)
 * [8 years ago](https://wordpress.org/support/topic/duplicate-events-in-database/#post-10176393)
 * Dude! I think you got it. With each successive sync there are (so far) no duplicates
   being created – data looks clean. Nice job!
 * One thing to note for anyone else who runs into this issue. After updating to
   plugin version 1.0.5, it DOES NOT clean up the previous duplicates in the database.
   So I removed all events, then did a sync. Seems to be good after that.
 * I’ll keep an eye on it for a week or so to ensure no issues, but all signs are
   positive.
 * Thanks for killer plugin support, Jared! I usually just write my own plugins 
   as support tends to be poor, or none. But you’re doing a great job!
 * thanks,
    Matt-
 *  Plugin Author [Jared Cobb](https://wordpress.org/support/users/jaredcobb/)
 * (@jaredcobb)
 * [8 years ago](https://wordpress.org/support/topic/duplicate-events-in-database/#post-10176433)
 * That’s how I do!

Viewing 10 replies - 1 through 10 (of 10 total)

The topic ‘Duplicate Events in Database’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/church-community-builder-core-api_a6a5a5.
   svg)
 * [Church Community Builder Core API](https://wordpress.org/plugins/church-community-builder-core-api/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/church-community-builder-core-api/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/church-community-builder-core-api/)
 * [Active Topics](https://wordpress.org/support/plugin/church-community-builder-core-api/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/church-community-builder-core-api/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/church-community-builder-core-api/reviews/)

 * 10 replies
 * 2 participants
 * Last reply from: [Jared Cobb](https://wordpress.org/support/users/jaredcobb/)
 * Last activity: [8 years ago](https://wordpress.org/support/topic/duplicate-events-in-database/#post-10176433)
 * Status: resolved