Better Search and Polylang compatibility
<?php
/**
* Joins the taxonomy tables. Filters bsearch_posts_join.
*
* @param string $join
* @return string
*/
function filter_bsearch_posts_join( $join ) {
global $wpdb;
return $join . "
INNER JOIN " . $wpdb->term_relationships . " ON (R.`post_id` = " . $wpdb->term_relationships . ".object_id)
INNER JOIN " . $wpdb->term_taxonomy . " ON (" . $wpdb->term_relationships . ".term_taxonomy_id = " . $wpdb->term_taxonomy . ".term_taxonomy_id)
";
}
add_filter( 'bsearch_posts_join', 'filter_bsearch_posts_join' );
/**
* Select posts from the same language. Filters bsearch_posts_where.
*
* @param string $where
* @return string
*/
function filter_bsearch_posts_where( $where ) {
global $wpdb;
return $where . "
AND " . $wpdb->term_taxonomy . ".taxonomy = 'language'
AND " . $wpdb->term_taxonomy . ".term_id IN ( SELECT TT.term_id FROM " . $wpdb->term_taxonomy . " TT INNER JOIN " . $wpdb->term_relationships . " TR ON TR.term_taxonomy_id = TT.term_taxonomy_id WHERE TR.object_id = " . $post_id . " )
";
}
add_filter( 'bsearch_posts_where', 'filter_bsearch_posts_where' );