Advertisement
eventsmanager

Events Manager WPML Integration

Apr 10th, 2012
708
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function em_wpml_integration($conditions, $args){
  2.     global $wpdb;
  3.     if( defined('ICL_LANGUAGE_CODE') ){
  4.         $conditions['wpml'] = EM_EVENTS_TABLE.'.post_id IN (SELECT element_id FROM '.$wpdb->prefix."icl_translations WHERE language_code ='".ICL_LANGUAGE_CODE."' AND element_type='post_".EM_POST_TYPE_EVENT."')";
  5.     }
  6.     return $conditions;
  7. }
  8. add_filter('em_events_build_sql_conditions','em_wpml_integration',10,2);
  9.  
  10. function em_wpml_integration_locations($conditions, $args){
  11.     global $wpdb;
  12.     if( defined('ICL_LANGUAGE_CODE') ){
  13.         $conditions['wpml'] = EM_LOCATIONS_TABLE.'.post_id IN (SELECT element_id FROM '.$wpdb->prefix."icl_translations WHERE language_code ='".ICL_LANGUAGE_CODE."' AND element_type='post_".EM_POST_TYPE_LOCATION."')";
  14.     }
  15.     return $conditions;
  16. }
  17. add_filter('em_locations_build_sql_conditions','em_wpml_integration_locations',10,2);
  18.  
  19. function em_wmpl_location_save($result, $EM_Location){
  20.     global $wpdb;
  21.     if( !$wpdb->get_var("SELECT translation_id FROM {$wpdb->prefix}icl_translations WHERE element_id=$EM_Location->post_id") ){
  22.         //save a value into WPML table
  23.         $wpdb->insert($wpdb->prefix.'icl_translations', array('element_type'=>"post_".EM_POST_TYPE_LOCATION, 'trid'=>$EM_Location->post_id, 'element_id'=>$EM_Location->post_id, 'language_code'=>ICL_LANGUAGE_CODE));
  24.     }
  25.     return $result;
  26. }
  27. add_filter('em_location_save','em_wmpl_location_save',10,2);
Advertisement
RAW Paste Data Copied
Advertisement