Last active
June 4, 2020 20:48
-
-
Save janneleppanen/087d1559bfd86977deaea3bc1711f239 to your computer and use it in GitHub Desktop.
ElasticPress - Polylang
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Filter Elasticsearch posts by current language | |
add_filter( 'ep_formatted_args', function($formatted_args, $args) { | |
$formatted_args['post_filter']['bool']['must'][] = [ | |
'term' => [ | |
'lang' => pll_current_language() | |
] | |
]; | |
return $formatted_args; | |
}, 10, 2); | |
// Add language data to Elasticsearch database | |
add_filter('ep_post_sync_args_post_prepare_meta', function($post_args, $post_id) { | |
$post_args['lang'] = pll_get_post_language($post_id); | |
return $post_args; | |
}, 10, 2); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment