- This topic has 2 replies, 2 voices, and was last updated 10 years, 12 months ago by .
Viewing 3 posts - 1 through 3 (of 3 total)
Viewing 3 posts - 1 through 3 (of 3 total)
- The forum ‘Tips’ is closed to new topics and replies.
Events Made Easy › Forums › Tips › Feature Requests/Code Contribution to avoid duplicated Events
Tagged: duplicate
Hi Franky,
I came up with the following which I thought I’d share:
// Check for Possible Duplicate Events on same Date at same Location
function eme_check_duplicate_event($event) {
global $wpdb;
$possible_duplicates = $wpdb->get_var( "SELECT COUNT(*) FROM " . $wpdb->prefix . "eme_events WHERE event_start_date
= ‘$event[event_start_date]’ AND location_id
= $event[location_id] LIMIT 0 , 5″ );
$dupe_query = “SELECT COUNT(*) FROM ” . $wpdb->prefix . “eme_events WHERE event_start_date
= $event[event_start_date] AND location_id
= $event[location_id] LIMIT 0 , 5″;
if ($possible_duplicates > 0) {
echo ‘<div class=”updated”><h2>Warning: Events already exist at that location on the same date.</h2></div>’;
//exit;
}
}
add_action(’eme_insert_event_action’,’eme_check_duplicate_event’);
add_action(’eme_update_event_action’,’eme_check_duplicate_event’);
I’ve added it to my functions.php but feel free to add it to the source if you want.
Thanks
Tom
Thanks for the contrib, but I can’t include it in the officical version (that’s why the hook exists of course), since many people do have more than one event at the same location (think about classes, fitness centers, etc …)
But your sql can be:
"SELECT COUNT(*) FROM " . $wpdb->prefix . "eme_events WHERE event_start_date = '".$event[event_start_date]."' AND location_id = ".$event[location_id]." LIMIT 1"
(I don’t know if the “LIMIT 1” will even gain some cpu cycles or not when using COUNT)
And you don’t seem to be using the $dupe_query variable 🙂
No worries.
I did think that which is why it just shows a warning and still inserts/updates the event. I thought a further development could be to enable/disable the warning in the options.
Yup – the variable was left in from when I was testing the query and forgot to remove it.
Thanks
Tom