Background of the issue:
I use WP Eventmanager Pro for event listing and user registrations for events. I add an event in German. The event has 8 registration spots. I have set automatic translation to English.
Symptoms:
The event is not just translated, it's being copied. So there are now two different events, with each 8 slots for registrations. It should be just 1 event (in German, translated to English) with 8 slots overall.
Questions:
What do I have to change to ensure that the event is translated and not duplicated?
Our compatibility team checked the issue and suggested the following workaround:
Open app/public/wp-content/plugins/wp-event-manager-registrations/wp-event-manager-registrations-functions.php
Around line 497, replace the following snippet:
if(!function_exists('get_event_registration_count')) {
/**
* Get number of registrations for a event
* @param int $event_id
* @return int
*/
function get_event_registration_count($event_id) {
return sizeof(get_posts(array(
'post_type' => 'event_registration',
'post_status' => array_merge(array_keys(get_event_registration_statuses()), array('publish')),
'posts_per_page' => -1,
'fields' => 'ids',
'post_parent' => $event_id
)));
}
}
With
if(!function_exists('get_event_registration_count')) {
/**
* Get number of registrations for a event
* @param int $event_id
* @return int
*/
function get_event_registration_count($event_id) {
// WPML workaround for compsupp-7562 - Part I
$translations = apply_filters( 'wpml_get_element_translations', null, $event_id, 'post_' . get_post_type($event_id) );
// Extract the IDs of the translated posts
$event_ids = array_map(function($translation) {
return $translation->element_id;
}, $translations);
// Get event registrations for all translations
return sizeof(get_posts(array(
'post_type' => 'event_registration',
'post_status' => array_merge(array_keys(get_event_registration_statuses()), array('publish')),
'posts_per_page' => -1,
'fields' => 'ids',
'post_parent__in' => $event_ids // Get all registrations for the event IDs
)));
}
}
Then, around line 595, replace the following snippet:
if(!function_exists('user_has_registered_for_event')) {
/**
* See if a user has already appled for a event
* @param int $user_id, $event_id
* @return int
*/
function user_has_registered_for_event($user_id, $event_id) {
if(!$user_id) {
return false;
}
return sizeof(get_posts(array(
'post_type' => 'event_registration',
'post_status' => array_merge(array_keys(get_event_registration_statuses()), array('publish')),
'posts_per_page' => 1,
'fields' => 'ids',
'post_parent' => $event_id,
'meta_query' => array(
array(
'key' => '_attendee_user_id',
'value' => absint($user_id)
)
)
)));
}
}
With
if(!function_exists('user_has_registered_for_event')) {
/**
* See if a user has already appled for a event
* @param int $user_id, $event_id
* @return int
*/
function user_has_registered_for_event($user_id, $event_id) {
if(!$user_id) {
return false;
}
// WPML Workaround for compsupp-7562 - Part II
$translations = apply_filters( 'wpml_get_element_translations', null, $event_id, 'post_' . get_post_type($event_id) );
// Extract the IDs of the translated posts
$event_ids = array_map(function($translation) {
return $translation->element_id;
}, $translations);
// Check if the user is registered for any translation of the event
return sizeof(get_posts(array(
'post_type' => 'event_registration',
'post_status' => array_merge(array_keys(get_event_registration_statuses()), array('publish')),
'posts_per_page' => 1,
'fields' => 'ids',
'post_parent__in' => $event_ids, // Check all event translations
'meta_query' => array(
array(
'key' => '_attendee_user_id',
'value' => absint($user_id)
)
)
))) > 0;
}
}
Let me know if this helps.
Thanks
The topic ‘[Closed] Events are duplicated not just translated’ is closed to new replies.