Plugin Author
Ajay
(@ajay)
Thanks so much, Ajay! So, I may need some additional guidance here. Where does this code go? Is there a file named same-language.php somewhere? If not, where do I create, and also curious how it will be picked up by CRP?
Plugin Author
Ajay
(@ajay)
You’ll need to add that code in your theme’s functions.php file which would be the best place to add it.
Got it. Thanks a lot, Ajay!
Hi @ajay and thanks for the plugin!
I’ve tried to add that code on the functions.php but similar posts are still mixed language. Please check out this post example:
https://thefoodellers.com/en/things-to-do-mauritius
In the similar posts box there are posts in italian…
@ajay We did apply the code to our staging environment and we are still seeing the same issue. Do you have any other suggestions?
https://wordpress-145745-1214197.cloudwaysapps.com/es/brasil-creme-de-papaya-crema-de-papaya/
You can see that the suggested French post does not have the /fr/ prefix in the URL, therefore creating a broken link.
Ideally, I would ONLY want suggest related posts in the same language ONLY (here Spanish in /es/ folder)
Plugin Author
Ajay
(@ajay)
I’m looking at the documentation of WPML again and I think the CRP implementation is outdated. I don’t have access to WPML, but would you be able to make edits to my plugin code as a test?
crp_object_id_cur_lang needs to be replaced with the below.
function crp_object_id_cur_lang( $post_id ) {
$return_original_if_missing = false;
$post = get_post( $post_id );
/**
* Filter to modify if the original language ID is returned.
*
* @since 2.2.3
*
* @param bool $return_original_if_missing
* @param int $post_id Post ID
*/
$return_original_if_missing = apply_filters( 'crp_wpml_return_original', $return_original_if_missing, $post_id );
// Polylang implementation.
if ( function_exists( 'pll_get_post' ) ) {
$post_id = pll_get_post( $post_id );
}
// WPML implementation.
$post_id = apply_filters( 'wpml_object_id', $post_id, $post->post_type, $return_original_if_missing );
/**
* Filters object ID for current language (WPML).
*
* @since 2.1.0
*
* @param int $post_id Post ID
*/
return apply_filters( 'crp_object_id_cur_lang', $post_id );
}
Hey @ajay , we tried this and it didn’t help. What would be the best way for me to give you access to our staging environment since you will have access to WPML too. My email is mike at 196flavors