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

WP Job Manager
Relevanssi doesn’t work with the WP Job Manager search. The solution is fortunately simple: you can just disable Relevanssi for…
ACF: Indexing relationship content
If your posts include content from related posts using the Advanced Custom Fields relationship functionality, Relevanssi doesn’t index that content…
Direct access to the query engine
Relevanssi can’t be used in any situation, because it checks the presence of search with the is_search() function. This causes some…

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