It appears the patch was included in change set 32293 (v4.3). However, the patch only applies to using add_rewrite_endpoint() to manage query vars. Nothing was changed regarding the query_vars filter behavior on home pages.
I advise you to use add_rewrite_endpoint() to add your query var instead of the query_vars filter.
Thank you very much for your reply.
For some reason, add_rewrite_endpoint doesn’t work for my site. Finally I found a solution. It’s a little complicated, but it works.
First, get the query var manually.
$this->base_path = parse_url(get_site_url())[‘path’];
preg_match(‘@’.$this->base_path.’\/(en|da|zh)\/?$@’, $_SERVER[‘REQUEST_URI’], $matches);
$this->qv = $matches[1];
Second, check the page type. If it is not the home page, add the customized query var. if it is the home page, DON’T ADD IT.
if(empty($this->qv) && rtrim($this->base_path, ‘/’) != rtrim($_SERVER[‘REQUEST_URI’], ‘/’)){
add_filter( ‘query_vars’, array($this, ‘add_custom_page_variables’) );
}
Finally, add the rewrite rules to validate the customized URL.
global $wp_rewrite;
$extra_rule[‘(‘.$this->langs_rex.’)/?$’] = ‘index.php?lang=$matches[1]’;
$wp_rewrite->rules = $extra_rule + $wp_rewrite->rules;
$wp_rewrite->flush_rules();
The last but not least, before all of these steps, the URL autocompletion function must be turned off, or the page will be directed to somewhere else. To turn off the function, please refer to http://geekwagner.blogspot.com/2017/02/wordpress-about-url-autocompletion.html
-
This reply was modified 7 years, 2 months ago by gongwan33.
-
This reply was modified 7 years, 2 months ago by gongwan33.