Making WPP really i18n with WPML
-
Hello,
since this topic, I was still fighting with your plugin, patching it and all, on every updates, without so much success, to make it really international and working with WPML.
So on the last update you made, I saw all the code changes, and the filters!!! I thought to put my code here for others whom are fighting with multilingual websites, with different content in each language.Here is my code I have put in theme’s
functions.php
file:/** * Alter WPP handling of WPML filter */ function wpp_i18n($post, $post_object, $options){ $tid = apply_filters( 'wpml_object_id', $post_object->id, 'post', false, ICL_LANGUAGE_CODE ); return $tid ? $post : false; } add_filter( 'wpp_post', 'wpp_i18n', 30, 3 ); /** * Alter query to show PP of the current language * */ // FIELD function wpp_i18n_query_fields( $fields, $options){ global $wpdb; return "DISTINCT wpml.language_code AS lg, " . $fields; // only the DISTINCT part is important here. } add_filter( 'wpp_query_fields', 'wpp_i18n_query_fields', 10, 2 ); // JOIN function wpp_i18n_query_join( $join, $options){ global $wpdb; $join .= " JOIN {$wpdb->prefix}icl_translations wpml ON p.ID = wpml.element_id AND wpml.element_type = CONCAT('post_', p.post_type)"; return $join; } add_filter( 'wpp_query_join', 'wpp_i18n_query_join', 10, 2 ); // WHERE function wpp_i18n_query_where( $where, $options){ global $wpdb; $args = array('post'); $where .= " AND wpml.language_code = '" . ICL_LANGUAGE_CODE . "' AND wpml.element_id = v.postid"; $where = $wpdb->prepare( $where, $args ); return $where; } add_filter( 'wpp_query_where', 'wpp_i18n_query_where', 10, 2 );
Thank you for your plugin and have a nice day.
EDIT: I try to put backticks around
{$wpdb->prefix}icl_translations
with no success because they are transformed with the<code></code>
tag :-), but I have put theme in my original code
- The topic ‘Making WPP really i18n with WPML’ is closed to new replies.