Forum Replies Created

Viewing 6 replies - 1 through 6 (of 6 total)
  • Thread Starter rahyong

    (@rahyong)

    Hi,

    Yes, you should be able to add the code to functions.php in your custom theme. In the solution that I provided, it is necessary to re-index in Elastic plugin for each WPML language after making the code update since it creates a separate Elasticsearch index for each language.

    Thread Starter rahyong

    (@rahyong)

    Paul, did you have to make any additional changes to get EP plugin to push all language content to ES when using a single index? In my initial tests, EP would only push content for the currently active language.

    Thread Starter rahyong

    (@rahyong)

    For those that want to use a filter and not update the core code:

    function filter_ep_formatted_args($formatted_args, $args) {
    	$new_formatted_args = $formatted_args;	
    
    	// Update each $formatted_args["filter"]["and"]["bool"]["must"]["terms"] to expand terms into
    	// array using comma delimiter
    	if ( ! empty($formatted_args["filter"]["and"]) ) {
    		for ( $and_ix=0; $and_ix<count($formatted_args["filter"]["and"]); $and_ix++ ) {
    			if ( ! empty( $formatted_args["filter"]["and"][$and_ix]["bool"]["must"] ) ) {
    				for ( $must_ix=0; $must_ix < count($formatted_args["filter"]["and"][$and_ix]["bool"]["must"]); $must_ix++ ) {
    					if ( ! empty($formatted_args["filter"]["and"][$and_ix]["bool"]["must"][$must_ix]["terms"]) ) {
    						foreach ( $formatted_args["filter"]["and"][$and_ix]["bool"]["must"][$must_ix]["terms"] as $term_key => $term_value ) {
    								$new_formatted_args["filter"]["and"][$and_ix]["bool"]["must"][$must_ix]["terms"][$term_key] = explode(',',$term_value[0]);
    						} // foreach
    					} // if
    				} // for
    			} // if
    		} // for
    	} // if
    	return $new_formatted_args;
    } // filter_ep_formatted_args
    
    add_filter('ep_formatted_args', array($this,'filter_ep_formatted_args'), 10, 2);
    Thread Starter rahyong

    (@rahyong)

    This should work:

    // Over-ride index name to support WPML
    function filter_ep_index_name($index_name, $blog_id) {
    	// WPML support
    	if ( function_exists('icl_object_id') ) {
    		$site_url = get_site_url( $blog_id );
    		$site_url = preg_replace('/\/$/','',apply_filters( 'wpml_home_url', $site_url ));	
    
    		if ( ! empty( $site_url ) ) {
    			$index_name = preg_replace( '#https?://(www\.)?#i', '', $site_url );
    			$index_name = preg_replace( '#[^\w]#', '', $index_name ) . '-' . $blog_id;
    		} else {
    			$index_name = false;
    		}
    	} // if
    	return $index_name;
    } // filter_ep_index_name
    
    // Fix Index name
    add_filter('ep_index_name', array($this,'filter_ep_index_name'), 10, 2);
    Thread Starter rahyong

    (@rahyong)

    I think I found a solution for WPML by updating get_index_name in classes/class-ep-config.php. Indexing and search now appears to return correct language based results.

    $site_url = get_site_url( $blog_id );
    
    // WPML support
    if ( function_exists('icl_object_id') ) {
    	$site_url = preg_replace('/\/$/','',apply_filters( 'wpml_home_url', $site_url ));
    } // if

    We have also taken the 0.9.2 distribution and made tweaks to support multi-site (virtual directory and virtual host) with site specific IdPs on WordPress 4.2.7. Would you be interested in a copy of our changes? It would be great to get multi-site included with the core distribution.

Viewing 6 replies - 1 through 6 (of 6 total)