Skip to main contentSkip to footer

Polylang Pro has a feature to sync translations between posts. The problem with this and Relevanssi is that Relevanssi does not index the changes to the synced posts. With this filter function added to your site, Relevanssi will also index the synced posts:

add_action( 'save_post', 'index_post_in_all_languages' );
function index_post_in_all_languages( $post_id ) {
    if ( ! function_exists( 'pll_languages_list' ) ||
     ! function_exists( 'relevanssi_insert_edit' ) ) {
        return;
    }
    $all_languages      = pll_languages_list( ['fields' => 'slug'] );
    $post_language      = pll_get_post_language( $post_id, 'slug' );
    $languages_to_index = array_diff( $all_languages, [ $post_language] );
    foreach ( $languages_to_index as $lang ) {
        $post_id_to_index = pll_get_post( $post_id, $lang );
        if ( $post_id_to_index > 0 ) {
            relevanssi_insert_edit( $post_id_to_index );
        }
    }
}

Thanks to Nico von Niederhäusern / Cubetech.

There’s also a method for indexing WPML synced posts.

Your account

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

Search

Popular Resources

Indexing term slugs
I have a term who name is for, example, Great Blue Trojans. The slug is GBT.I want to be able…
Searching Bible verses
A surprisingly common problem with Relevanssi is Bible verses. All that meaningful punctuation and single digits make exact matching of…

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