Hi!
Can anyone could help me with the trouble of showing posts only in the default language?
Thanks!
Plugin Author
Chouby
(@chouby)
Hi!
I’ve done pasted the code in that page to my functions.php and then the page shows in blank, the admin and the front-end too.
You probably did something wrong. Blank page generally means a fatal error. Set WP_DEBUG to true in wp-config.php to display errors (don’t forget to set it to false once the problem is solved).
This is what the debug returned
Notice: Use of undefined constant E_USER_DEPRECATED - assumed 'E_USER_DEPRECATED' in /usr/home/suvisa/www/wordpress/wp-content/plugins/codestyling-localization/codestyling-localization.php on line 2491
Notice: Trying to get property of non-object in /usr/home/suvisa/www/wordpress/wp-content/themes/kallyas/header.php on line 147
Plugin Author
Chouby
(@chouby)
Strange. Notices should not break the site. Only errors can leave a site blank. Sorry this cannot help to find out what’s wrong.
I don’t know why but now does not show the blank page, but still doesn’t show the default post…
The code i put in the functions.php with the Functionality plugin is this:
add_filter( 'pre_get_posts', 'get_default_language_posts' );
function get_default_language_posts( $query ) {
if ( $query->is_main_query() && function_exists('pll_default_language') && !is_admin()){
$terms = get_terms('post_translations'); //polylang stores translated post IDs in a serialized array in the description field of this custom taxonomy
$defLang = pll_default_language(); //default lanuage of the blog
$curLang = pll_current_language(); //current selected language requested on the broswer
$filterPostIDs = array();
foreach($terms as $translation){
$transPost = unserialize($translation->description);
//if the current language is not the default, lets pick up the default language post
if($defLang!=$curLang) $filterPostIDs[]=$transPost[$defLang];
}
if($defLang!=$curLang){
$query->set('lang' , $defLang.','.$curLang); //select both default and current language post
$query->set('post__not_in', $filterPostIDs); // remove the duplicate post in the default language
}
}
return $query;
}
Thanks for your help!
So… anyone could help me? Anyone needs to use the default language instead of the secondary ones?
Thanks!