• 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

    • This topic was modified 7 years, 1 month ago by anou. Reason: backticks escape
    • This topic was modified 7 years, 1 month ago by anou. Reason: backticks escape
    • This topic was modified 7 years, 1 month ago by anou.
    • This topic was modified 7 years, 1 month ago by anou.
    • This topic was modified 7 years, 1 month ago by anou.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Hector Cabrera

    (@hcabrera)

    Hey @anou,

    Just a heads-up: I made a change to the code that will probably break what you posted here. You might want to review it.

    Thread Starter anou

    (@anou)

    Hi @hcabrera

    Thx for the info. I’ve made the changes on my local dev without problem with my code.

    Only had to comment a part that I fought a lot to find to make my query work :-):

    In wpp_i18n_query_where(), I can comment the prepare query part: //$where = $wpdb->prepare( $where, $args );

    This is how you learn ?? and thanks to you I’m ready for the next update.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Making WPP really i18n with WPML’ is closed to new replies.