Skip to content

Instantly share code, notes, and snippets.

@msaari
Last active February 1, 2019 04:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save msaari/d35b72ea08ae998e552fe13d8e8e6d68 to your computer and use it in GitHub Desktop.
Save msaari/d35b72ea08ae998e552fe13d8e8e6d68 to your computer and use it in GitHub Desktop.
Relevanssi Langwitch support
<?php
// Add these to theme functions.php and go save the pages.
add_filter( 'relevanssi_content_to_index', 'rlv_langwitch_elements', 10, 2 );
function rlv_langwitch_elements( $content, $post ) {
$elements = get_option( '_alt_langwitch_elements_opts_page_' . $post->ID );
$element_content = '';
foreach ( $elements as $item ) {
$value = rlv_process_array( $item );
if ( ! empty( $value ) ) {
$element_content .= ' ' . $value;
}
}
$content .= $element_content;
return $content;
}
function rlv_process_array( $array ) {
foreach ( $array as $key => $value ) {
if ( 'es_ES' === $key ) {
return $value;
}
if ( is_array( $value ) ) {
$value = rlv_process_array( $value );
if ( $value ) {
return $value;
}
}
}
return $value;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment