Skip to main contentSkip to footer

When a post is updated, WPML updates all the translations of the post, but Relevanssi only indexes the post that was updated, not the corresponding posts in other languages. This method hooks into save_post after WPML to tell Relevanssi also to index the matching translations.

add_action( 'save_post', 'index_post_in_all_languages', 110, 2 );
function index_post_in_all_languages( $post_ID, $post ) {
	if ( ! function_exists( 'relevanssi_insert_edit' ) ) {
		return;
	}
    $trid = apply_filters( 'wpml_element_trid', null, $post_ID, "post_{$post->post_type}" );
    if ( ! $trid ) {
    	return;
    }
    $translations = apply_filters( 'wpml_get_element_translations', null, $trid, $post->post_type );
	foreach ( $translations as $lang => $translation ) {
		$translation_id = absint( $translation->element_id );
        if ( ! empty( $translation_id ) && $translation_id !== $post_ID ) {
			relevanssi_insert_edit( $translation_id );
        }
    }
}

Thanks to Garrett McGilvray / Éditions CEB.

There’s a similar solution for Polylang Pro synced posts.

Your account

Not logged in. Log in to see your license details.

Search

Popular Resources

OceanWP
OceanWP is a popular WordPress theme. It works fine with Relevanssi, but how it handles excerpts on the search results…
bbPress: Private Groups support
Private Groups is a plugin that makes bbPress forum groups private. Relevanssi, however, doesn’t understand that privacy and will show…
Polylang: Bilingual search
By default, Relevanssi indexes the different language versions of the posts separately. If your site is in French and English,…

Related Posts:

Comment Section:

Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.
You need to agree with the terms to proceed