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

Ultimate FAQs
Ultimate FAQs is a FAQ plugin that can create FAQs. It has a search, and enabling Relevanssi may break that…
Taxonomy archive search
This is a Premium feature and only applies when you index taxonomy terms. This does not apply in free Relevanssi.…

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