Closed heymATIN closed 8 years ago
I am looking into the code you provided to see how it works. Could you explain what is not working? What breaks?
When using the code snippet you showed do you create a dummy translate post or do you just have the default translation page?
I actually have no clue what happens there. I took this code from here: http://wordpress.syllogic.in/2014/08/going-multi-lingual-with-polylang/ .
I got redirected to that site from the documentation: https://polylang.wordpress.com/documentation/documentation-for-developers/tips-and-tricks/how-to-display-the-default-language-post-if-the-translation-does-not-exists/
So what that code does is that - if you do not have a translation to a post, it still shows the default translation.
Example: If I switched to the german langauge, and I have 15 posts in english, and only translated 3 posts to german. I still get all posts. 12 in english + 3 in german. Non translated posts (default english) + translated posts (german).
Edit*
And For some reason, if I use both plugins, the mixing of langauges does not work.
A temp solution would be to comment out these two lines of code in my plugin.
//add_filter( 'posts_where', 'polylang_slug_posts_where_filter', 10, 2 );
//add_filter( 'posts_join', 'polylang_slug_posts_join_filter', 10, 2 );
I will try and see if there is a better solution
Yeah can confirm that worked! I still will check for updates. Thanks a lot. Much appreciated!
It does it job. When I want to mix two languages.
But it breaks other things and starts to redirect in a infinity loop on other pages that has the same slug.
Example: I can mix my blogposts in english and swedish. But when I have two pages: www.url.com/client/client-1 www.url.com/en/client/client-1 it starts redirecting "301 Moved Permanently" and I am not able to browse any of the page.
Is there any other way around this?
EDIT: @heymATIN @grappler This seems to solve my issue:
function polylang_slug_posts_where_filter( $where, $query ) {
global $polylang;
if ( is_admin() || ! empty( $query->query['post_type'] ) && ! $polylang->model->is_translated_post_type( $query->query['post_type'] ) ) {
return $where;
}
// I added this
if( !empty( $query->query['lang'] ) ) {
return $where;
}
$lang = pll_current_language();
// " AND pll_tr.term_taxonomy_id IN (" . implode(',', $languages) . ")"
$where .= $polylang->model->where_clause( $lang, 'post' );
return $where;
}
If I set lang in the query then I shouldnt add the default one again and just return the where-query as it is.
Thank you @adamlindqvist I will be adding your fix to the next version.
@heymATIN It seems to fix your problem.
I was using this code to display the default langauge for not translated languages in the current language:
Since using your plugin it does not work anymore :/
Is it possible for you to fix it? I need both very badly!
And thanks a lot for that great plugin!!