Viewing 3 replies - 16 through 18 (of 18 total)
  • Hi again,

    I found the code and I fixed it, here is my result:

    add_action( 'after_setup_theme', 'relevanssi_custom_setup' );
    
    function relevanssi_custom_setup(){
        if (defined('ICL_LANGUAGE_CODE'))
    	add_filter('relevanssi_hits_filter', 'relevanssi_wpml_filter');
    }
    
    // thanks to rvencu
    function relevanssi_wpml_filter($data) {
    	if (function_exists(icl_object_id)) {
    		$filtered_hits = array();
        	foreach ($data[0] as $hit) {
            	if ($hit->ID == icl_object_id($hit->ID, $hit->post_type,false,ICL_LANGUAGE_CODE))
                    $filtered_hits[] = $hit;
    	    }
    	    return array($filtered_hits,$data[1]);
    	}
    	else {
    		return $data;
    	}
    }

    Note that you missed a $hits[1] instead of $data[1].
    Also at the time your plugin loads the filter does not get applied. If waiting until after the theme setup is helping the process. At least in my installation it works like this.

    Plugin Author Mikko Saari

    (@msaari)

    Thanks for being so alert! However, just upgrade to 2.7.1, that fixes it.

    There were two problems: function_exists needs quotes around the function name and the if(defined()) contruction doesn’t work unless you do something like you did.

    The $hits[1] doesn’t matter, because that return value is never used, it’s only to give some extra information to the filter.

    I’ll probably fix it to something like this eventually, but right now, 2.7.1 works and 2.7 doesn’t.

    Perfect. Thanks and congratulations for such a great plugin!

Viewing 3 replies - 16 through 18 (of 18 total)
  • The topic ‘[Plugin: Relevanssi – A Better Search] Compatibility with WPML’ is closed to new replies.