admin管理员组文章数量:1314496
I have a custom post type "press-release" that I pass a query var to the template through the URL. The URL structure looks like this.
MYDOMAIN.COM/press-release/TITLE-OF-RELEASE/?client=123
When I go to the url everything works as expected. I am able to grab the value from the query var. The issue I have is on page load Wordpress then rewrites the URL to be:
MYDOMAIN.COM/press-release/TITLE-OF-RELEASE/
I need to keep the query var in the URL structure so people can share the URL.
I have tried many options but no success so far. Does anyone know why Wordpress is doing this and how it can be fixed so my query var does not get removed from the URL?
UPDATE: I have tried this but no success
add_action('init', 'add_client_url');
function add_client_url() {
global $wp,$wp_rewrite;
$wp->add_query_var('client');
$wp_rewrite->add_rule('client/([^/]+)','index.php?client=$matches[1]','top');
$wp_rewrite->flush_rules(false);
}
UPDATE 2: I was able to get it to work with this code...
add_action( 'init', 'pmg_rewrite_add_rewrites' );
function pmg_rewrite_add_rewrites()
{
add_rewrite_endpoint( 'client', EP_PERMALINK );
}
However, the URL now requires MYDOMAIN.COM/press-release/TITLE-OF-RELEASE/client/123
Does anyone know how to make it work like this? MYDOMAIN.COM/press-release/TITLE-OF-RELEASE/123
UPDATE 3: here is the current .htaccess
# BEGIN WordPress
# The directives (lines) between "BEGIN WordPress" and "END WordPress" are
# dynamically generated, and should only be modified via WordPress filters.
# Any changes to the directives between these markers will be overwritten.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
本文标签: permalinksWordpress keeps removing query var from the URL
版权声明:本文标题:permalinks - Wordpress keeps removing query var from the URL 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741968018a2407662.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论