最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

permalinks - Wordpress keeps removing query var from the URL

programmeradmin0浏览0评论

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
发布评论

评论列表(0)

  1. 暂无评论