Plugin Author
Ajay
(@ajay)
This will need to have a rewrite of the function. Alternatively, you can modify the results once they are retrieved similar to how it is implemented in get_crp
https://github.com/WebberZone/contextual-related-posts/blob/master/contextual-related-posts.php#L190-L196
I’ll need to experiment with the latter
For the moment I’ve changed the query to select only posts from the current language:
$sql = “SELECT DISTINCT $fields FROM $wpdb->posts inner join wp_icl_translations on wp_icl_translations.element_id = wp_posts.ID WHERE 1=1 AND wp_icl_translations.language_code='” . ICL_LANGUAGE_CODE . “‘ $where $groupby $having $orderby $limits”;
Plugin Author
Ajay
(@ajay)
You could do this a bit cleaner in that case by using a function to
function same_language_crp( $where ) {
$where .= " AND wp_icl_translations.language_code='" . ICL_LANGUAGE_CODE . "' ";
return $where;
}
add__filter( 'crp_posts_where', 'same_language_crp' );
Yes I’ll do it and I’ll add a filter for the join as well 🙂
my 2cents on this:
function same_language_crp_join( $join ) {
global $wpdb;
$join .= " INNER JOIN " . $wpdb->prefix . "icl_translations";
$join .= " ON " . $wpdb->prefix . "icl_translations.element_id = " . $wpdb->posts . ".ID";
return $join;
}
add_filter( 'crp_posts_join', 'same_language_crp_join' );
function same_language_crp_where( $where ) {
global $wpdb;
$where .= " AND " . $wpdb->prefix . "icl_translations.language_code='" . ICL_LANGUAGE_CODE . "' ";
return $where;
}
add_filter( 'crp_posts_where', 'same_language_crp_where' );
Plugin Author
Ajay
(@ajay)
Thanks. This definitely looks complete.
@pixael does this work for you?
Sorry for not getting back to you @ajay!
Yes, this is almost exactly what I did to get the same query I posted with the correct filters.