Title: muh's Replies | WordPress.org

---

# muh

  [  ](https://wordpress.org/support/users/muh/)

 *   [Profile](https://wordpress.org/support/users/muh/)
 *   [Topics Started](https://wordpress.org/support/users/muh/topics/)
 *   [Replies Created](https://wordpress.org/support/users/muh/replies/)
 *   [Reviews Written](https://wordpress.org/support/users/muh/reviews/)
 *   [Topics Replied To](https://wordpress.org/support/users/muh/replied-to/)
 *   [Engagements](https://wordpress.org/support/users/muh/engagements/)
 *   [Favorites](https://wordpress.org/support/users/muh/favorites/)

 Search replies:

## Forum Replies Created

Viewing 8 replies - 1 through 8 (of 8 total)

 *   Forum: [Plugins](https://wordpress.org/support/forum/plugins-and-hacks/)
    In
   reply to: [[xili-language] SQL Error after custom pre_get_posts hook](https://wordpress.org/support/topic/sql-error-after-custom-pre_get_posts-hook/)
 *  Thread Starter [muh](https://wordpress.org/support/users/muh/)
 * (@muh)
 * [12 years, 3 months ago](https://wordpress.org/support/topic/sql-error-after-custom-pre_get_posts-hook/#post-4893485)
 * Sorry for the delay. Let put my 2nd issue aside and go back to the first.
 * I wrote a little update to handle post type that aren’t authorized so they will
   be displayed on the page. Otherwise only authorized types with the correct language
   are displayed.
 *     ```
       $notAuthorizedTypes = array();
       if ( empty( $query_object->query_vars['post_type'] ) ) { // string or array
       	$insertWhere = true;
       } else if ( is_string($query_object->query_vars['post_type']) && in_array ( $query_object->query_vars['post_type'], array_keys ( $this->authorized_custom_post_type () ) ) ){
       	$insertWhere = true;
       } else if (is_array($query_object->query_vars['post_type'])){
       	$insertWhere = true;
       	$authorized = $this->authorized_custom_post_type();
       	foreach($query_object->query_vars['post_type'] as $postType){
       		if (!isset($authorized[$postType]) || $authorized[$postType]['multilingual'] != 'enable'){
       			$notAuthorizedTypes[] = $postType;
       		}
       	}
       } else {
       	$insertWhere = false;
       }
       if ( $insertWhere ){
       	$query_object->query_vars[QUETAG] = $curlang; // in query.php posts_join filter is called after posts_where filter - for home page without lang_quetag
       	$need_join = true;
       	$wherereqtag = $this->langs_ids_array[$curlang];
       	$where .= ' AND (';
       	$where .= "(xtt.taxonomy = '" . TAXONAME . "' "; //"
       	$where .= " AND xtt.term_id = $wherereqtag )";
       	if (count($notAuthorizedTypes)){
       		$where .= ' OR ';
       		$where .= 'post_type IN (\''.implode('\', \'', $notAuthorizedTypes).'\')';
       	}
       	$where .= ')';
   
       }
       ```
   
 * **Edit: ** Besides you couldn’t deauthorize post types. Once they were authorized
   they always were. The same problem occures if the post_type index is a string:
   `}
   else if ( is_string($query_object->query_vars['post_type']) && in_array ( $query_object-
   >query_vars['post_type'], array_keys ( $this->authorized_custom_post_type () ))){`
 * You’re just checking if the authorized array contains the post_type but you aren’t
   checking if it’s enabled or not. I think you can fix this yourself. 😉
 * _– Simon_
 *   Forum: [Plugins](https://wordpress.org/support/forum/plugins-and-hacks/)
    In
   reply to: [[xili-language] SQL Error after custom pre_get_posts hook](https://wordpress.org/support/topic/sql-error-after-custom-pre_get_posts-hook/)
 *  Thread Starter [muh](https://wordpress.org/support/users/muh/)
 * (@muh)
 * [12 years, 3 months ago](https://wordpress.org/support/topic/sql-error-after-custom-pre_get_posts-hook/#post-4893461)
 * I think that will be the problem. My plugin translations are not located in the
   local-xx_YY file but in the wp-content/languages/plugins/pluginname-xx_YY.mo 
   files.
 * I’m sorry but I can’t contact you from the support tab. What infos do you need?
 *   Forum: [Plugins](https://wordpress.org/support/forum/plugins-and-hacks/)
    In
   reply to: [[xili-language] SQL Error after custom pre_get_posts hook](https://wordpress.org/support/topic/sql-error-after-custom-pre_get_posts-hook/)
 *  Thread Starter [muh](https://wordpress.org/support/users/muh/)
 * (@muh)
 * [12 years, 3 months ago](https://wordpress.org/support/topic/sql-error-after-custom-pre_get_posts-hook/#post-4893458)
 * I just solved my next issue with the translation of the page. You’re plugin works
   as intended, but.. 😉
 * I don’t know if I broke it or if xili-language just don’t support the translation
   of plugins. That’s why I created a little extension as a separate plugin for 
   xili-language.
 * I’m not very experienced in the internal l10n functions of wp, so I hope you 
   don’t blame me if I did something wrong.
 * Maybe you want to merge it to xili-language or release it as a separate plugin
   or so. I won’t do anything with the code as long as it works. You may change 
   the copyright, I don’t really care. So do as you please, even if you ignore it.
   I just wanted to share this with you:
 *     ```
       class xili_language_plugins {
   
       	protected $oldlang;
       	protected $curlang;
   
       	public function __construct( ) {
       		if (is_admin())
       			return;
       		$this->domains = array();
       		add_action('init', array($this,'loaded'));
       		add_filter('load_textdomain_mofile', array($this,'load_textdomain'),10,2);
       	}
   
       	public function loaded(){
       		if (!isset($GLOBALS['xili_language']))
       			return;
       		$this->xili_lang = $GLOBALS['xili_language'];
   
       		$this->curlang = get_locale();
       		add_filter('locale', array($this,'locale'));
       	}
   
       	public function load_textdomain($moFile, $domain){
       		$this->domains[$domain] = $moFile;
       		return $moFile;
       	}
   
       	protected function replace_text_domains(){
       		foreach ($this->domains as $domain => $moFile){
       			unload_textdomain($domain);
       			load_textdomain($domain, str_replace($this->oldlang, $this->correct_case($this->curlang),$moFile));
       		}
       	}
   
       	protected function correct_case($lang){
       		list($lang,$country) = explode('_',$lang);
       		return strtolower($lang).'_'.strtoupper($country);
       	}
   
       	public function locale($current){
       		if (!isset($this->xili_lang))
       			return $current;
       		if ($this->xili_lang->curlang != $this->curlang){
       			$this->oldlang = $this->curlang;
       			$this->curlang = $this->xili_lang->curlang;
       			$this->replace_text_domains();
       		}
       		return $current;
       	}
   
       } /* **************** end of xili-language-plugin class ******************* */
   
       /****************** instantiation Class *****************/
   
       /**
        * instantiation of xili_language_plugins class
        */
       function xili_language_plugins_start () {
       	global $xili_language_plugin;
       	$xili_language_plugin = new xili_language_plugins( false , false );
       }
       xili_language_plugins_start();
       ```
   
 * and yes, I copied a bit of your code. And sorry for using the name prefix ‘xili’.
 *   Forum: [Plugins](https://wordpress.org/support/forum/plugins-and-hacks/)
    In
   reply to: [[xili-language] SQL Error after custom pre_get_posts hook](https://wordpress.org/support/topic/sql-error-after-custom-pre_get_posts-hook/)
 *  Thread Starter [muh](https://wordpress.org/support/users/muh/)
 * (@muh)
 * [12 years, 3 months ago](https://wordpress.org/support/topic/sql-error-after-custom-pre_get_posts-hook/#post-4893457)
 * Thanks for the update. I just installed it. Seems to work fine.
 *   Forum: [Plugins](https://wordpress.org/support/forum/plugins-and-hacks/)
    In
   reply to: [[xili-language] SQL Error after custom pre_get_posts hook](https://wordpress.org/support/topic/sql-error-after-custom-pre_get_posts-hook/)
 *  Thread Starter [muh](https://wordpress.org/support/users/muh/)
 * (@muh)
 * [12 years, 3 months ago](https://wordpress.org/support/topic/sql-error-after-custom-pre_get_posts-hook/#post-4893334)
 * You’re welcome. Thanks for your fast and good feedback.
 * I’m looking forward for the new version.
 * Thanks
    Simon
 *   Forum: [Plugins](https://wordpress.org/support/forum/plugins-and-hacks/)
    In
   reply to: [[xili-language] SQL Error after custom pre_get_posts hook](https://wordpress.org/support/topic/sql-error-after-custom-pre_get_posts-hook/)
 *  Thread Starter [muh](https://wordpress.org/support/users/muh/)
 * (@muh)
 * [12 years, 3 months ago](https://wordpress.org/support/topic/sql-error-after-custom-pre_get_posts-hook/#post-4893312)
 * I also modified the _posts\_where\_lang_-Function because of the same problem.
   xlil-language.php:~1564 (the 2.9.2 section):
 *     ```
       $insertWhere = false;
       if ($query_object->query_vars['post_type'] == ''){
       	$insertWhere = true;
       }else if (is_string($query_object->query_vars['post_type']) && in_array ( $query_object->query_vars['post_type'], array_keys ($this->authorized_custom_post_type () ) )){
       	$insertWhere = true;
       }else if (is_array($query_object->query_vars['post_type']) && !count(array_diff($query_object->query_vars['post_type'],array_keys($this->authorized_custom_post_type())))){
       	$insertWhere = true;
       }
       if ($insertWhere){
       	$query_object->query_vars['lang'] = $curlang;
       	$wherereqtag = $this->langs_ids_array[$curlang];
       	$where .= " AND xtt.taxonomy = '" . TAXONAME . "' "; //"
       	$where .= " AND xtt.term_id = $wherereqtag ";
       }
       ```
   
 *   Forum: [Plugins](https://wordpress.org/support/forum/plugins-and-hacks/)
    In
   reply to: [[xili-language] SQL Error after custom pre_get_posts hook](https://wordpress.org/support/topic/sql-error-after-custom-pre_get_posts-hook/)
 *  Thread Starter [muh](https://wordpress.org/support/users/muh/)
 * (@muh)
 * [12 years, 3 months ago](https://wordpress.org/support/topic/sql-error-after-custom-pre_get_posts-hook/#post-4893299)
 * Ok, you were right. To modify $this->sublang wasn’t that good as I thought.
 * But now im sure I’ve found the bug.
 * xili-language.php:1274
 *     ```
       if ( is_admin () || in_array ( $query_object->query_vars['post_type'], array_keys ($this->authorized_custom_post_type () ) ) )
       	$insert_join = true;
       ```
   
 * You’re assuming that query_vars[‘post_type’] is just a string. But in my case
   it’s an array of strings.
 * Possible solution:
 *     ```
       if (is_admin()){
       	$insert_join = true;
       }else if (is_string($query_object->query_vars['post_type']) && in_array ( $query_object->query_vars['post_type'], array_keys ($this->authorized_custom_post_type () ) )){
       	$insert_join = true;
       }else if (is_array($query_object->query_vars['post_type']) && !count(array_diff($query_object->query_vars['post_type'],array_keys($this->authorized_custom_post_type())))){
       	$insert_join = true;
       }
       ```
   
 * But careful: This will only work if all selected custom post types are authorized.
   As soon as one of them isn’t authorized there will be the same SQL Error.
 * Maybe you want to filter the post types or modify the query to select all of 
   the non authorized posts and only the subset of the authorized.
 *   Forum: [Plugins](https://wordpress.org/support/forum/plugins-and-hacks/)
    In
   reply to: [[xili-language] SQL Error after custom pre_get_posts hook](https://wordpress.org/support/topic/sql-error-after-custom-pre_get_posts-hook/)
 *  Thread Starter [muh](https://wordpress.org/support/users/muh/)
 * (@muh)
 * [12 years, 3 months ago](https://wordpress.org/support/topic/sql-error-after-custom-pre_get_posts-hook/#post-4893290)
 * Because I want to display more than just ‘posts’ on my index page. I’ve added
   multiple different post types that have to be shown.
 * [Detailed Description](http://justintadlock.com/archives/2010/02/02/showing-custom-post-types-on-your-home-blog-page).

Viewing 8 replies - 1 through 8 (of 8 total)